<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"module-curses.panel.html" />
<link rel=
"prev" href=
"module-curses.wrapper.html" />
<link rel=
"parent" href=
"allos.html" />
<link rel=
"next" href=
"module-curses.panel.html" />
<meta name='aesop' content='information'
/>
<title>6.18 curses.ascii -- Utilities for ASCII characters
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.17 curses.wrapper "
href=
"module-curses.wrapper.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6. Generic Operating System"
href=
"allos.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.19 curses.panel "
href=
"module-curses.panel.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-curses.wrapper.html">6.17 curses.wrapper
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"allos.html">6. Generic Operating System
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-curses.panel.html">6.19 curses.panel
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION0081800000000000000000">
6.18 <tt class=
"module">curses.ascii
</tt> --
Utilities for ASCII characters
</A>
<A NAME=
"module-curses.ascii"></A>
<span class=
"versionnote">New in version
1.6.
</span>
The
<tt class=
"module">curses.ascii
</tt> module supplies name constants for
ASCII characters and functions to test membership in various
ASCII character classes. The constants supplied are names for
control characters as follows:
<div class=
"center"><table class=
"realtable">
<th class=
"left" >Name
</th>
<th class=
"left" >Meaning
</th>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">NUL
</tt></td>
<td class=
"left" ></td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">SOH
</tt></td>
<td class=
"left" >Start of heading, console interrupt
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">STX
</tt></td>
<td class=
"left" >Start of text
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">ETX
</tt></td>
<td class=
"left" >End of text
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">EOT
</tt></td>
<td class=
"left" >End of transmission
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">ENQ
</tt></td>
<td class=
"left" >Enquiry, goes with
<tt class=
"constant">ACK
</tt> flow control
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">ACK
</tt></td>
<td class=
"left" >Acknowledgement
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">BEL
</tt></td>
<td class=
"left" >Bell
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">BS
</tt></td>
<td class=
"left" >Backspace
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">TAB
</tt></td>
<td class=
"left" >Tab
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">HT
</tt></td>
<td class=
"left" >Alias for
<tt class=
"constant">TAB
</tt>: ``Horizontal tab''
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">LF
</tt></td>
<td class=
"left" >Line feed
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">NL
</tt></td>
<td class=
"left" >Alias for
<tt class=
"constant">LF
</tt>: ``New line''
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">VT
</tt></td>
<td class=
"left" >Vertical tab
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">FF
</tt></td>
<td class=
"left" >Form feed
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">CR
</tt></td>
<td class=
"left" >Carriage return
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">SO
</tt></td>
<td class=
"left" >Shift-out, begin alternate character set
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">SI
</tt></td>
<td class=
"left" >Shift-in, resume default character set
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">DLE
</tt></td>
<td class=
"left" >Data-link escape
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">DC1
</tt></td>
<td class=
"left" >XON, for flow control
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">DC2
</tt></td>
<td class=
"left" >Device control
2, block-mode flow control
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">DC3
</tt></td>
<td class=
"left" >XOFF, for flow control
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">DC4
</tt></td>
<td class=
"left" >Device control
4</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">NAK
</tt></td>
<td class=
"left" >Negative acknowledgement
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">SYN
</tt></td>
<td class=
"left" >Synchronous idle
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">ETB
</tt></td>
<td class=
"left" >End transmission block
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">CAN
</tt></td>
<td class=
"left" >Cancel
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">EM
</tt></td>
<td class=
"left" >End of medium
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">SUB
</tt></td>
<td class=
"left" >Substitute
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">ESC
</tt></td>
<td class=
"left" >Escape
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">FS
</tt></td>
<td class=
"left" >File separator
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">GS
</tt></td>
<td class=
"left" >Group separator
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">RS
</tt></td>
<td class=
"left" >Record separator, block-mode terminator
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">US
</tt></td>
<td class=
"left" >Unit separator
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">SP
</tt></td>
<td class=
"left" >Space
</td></tr>
<tr><td class=
"left" valign=
"baseline"><tt class=
"constant">DEL
</tt></td>
<td class=
"left" >Delete
</td></tr></tbody>
Note that many of these have little practical significance in modern
usage. The mnemonics derive from teleprinter conventions that predate
The module supplies the following functions, patterned on those in the
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2155' xml:id='l2h-
2155'
class=
"function">isalnum
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII alphanumeric character; it is equivalent to
"<tt class="samp
">isalpha(<var>c</var>) or isdigit(<var>c</var>)</tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2156' xml:id='l2h-
2156'
class=
"function">isalpha
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII alphabetic character; it is equivalent to
"<tt class="samp
">isupper(<var>c</var>) or islower(<var>c</var>)</tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2157' xml:id='l2h-
2157'
class=
"function">isascii
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for a character value that fits in the
7-bit ASCII set.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2158' xml:id='l2h-
2158'
class=
"function">isblank
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII whitespace character.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2159' xml:id='l2h-
2159'
class=
"function">iscntrl
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII control character (in the range
0x00 to
0x1f).
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2160' xml:id='l2h-
2160'
class=
"function">isdigit
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII decimal digit,
"<tt class="character
">0</tt>" through
"<tt class="character
">9</tt>". This is equivalent to
"<tt class="samp
"><var>c</var> in string.digits</tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2161' xml:id='l2h-
2161'
class=
"function">isgraph
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for ASCII any printable character except space.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2162' xml:id='l2h-
2162'
class=
"function">islower
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII lower-case character.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2163' xml:id='l2h-
2163'
class=
"function">isprint
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for any ASCII printable character including space.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2164' xml:id='l2h-
2164'
class=
"function">ispunct
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for any printable ASCII character which is not a space or an
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2165' xml:id='l2h-
2165'
class=
"function">isspace
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for ASCII white-space characters; space, line feed,
carriage return, form feed, horizontal tab, vertical tab.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2166' xml:id='l2h-
2166'
class=
"function">isupper
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII uppercase letter.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2167' xml:id='l2h-
2167'
class=
"function">isxdigit
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII hexadecimal digit. This is equivalent to
"<tt class="samp
"><var>c</var> in string.hexdigits</tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2168' xml:id='l2h-
2168'
class=
"function">isctrl
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for an ASCII control character (ordinal values
0 to
31).
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2169' xml:id='l2h-
2169'
class=
"function">ismeta
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Checks for a non-ASCII character (ordinal values
0x80 and above).
These functions accept either integers or strings; when the argument
is a string, it is first converted using the built-in function
<tt class=
"function">ord()
</tt>.
Note that all these functions check ordinal bit values derived from the
first character of the string you pass in; they do not actually know
anything about the host machine's character encoding. For functions
that know about the character encoding (and handle
internationalization properly) see the
<tt class=
"module"><a href=
"module-string.html">string
</a></tt> module.
The following two functions take either a single-character string or
integer byte value; they return a value of the same type.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2170' xml:id='l2h-
2170'
class=
"function">ascii
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Return the ASCII value corresponding to the low
7 bits of
<var>c
</var>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2171' xml:id='l2h-
2171'
class=
"function">ctrl
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Return the control character corresponding to the given character
(the character bit value is bitwise-anded with
0x1f).
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2172' xml:id='l2h-
2172'
class=
"function">alt
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Return the
8-bit character corresponding to the given ASCII character
(the character bit value is bitwise-ored with
0x80).
The following function takes either a single-character string or
integer value; it returns a string.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
2173' xml:id='l2h-
2173'
class=
"function">unctrl
</tt></b>(
</nobr></td>
<td><var>c
</var>)
</td></tr></table></dt>
Return a string representation of the ASCII character
<var>c
</var>. If
<var>c
</var> is printable, this string is the character itself. If the
character is a control character (
0x00-
0x1f) the string consists of a
caret (
"<tt class="character
">^</tt>") followed by the corresponding uppercase letter.
If the character is an ASCII delete (
0x7f) the string is
<code>'^?'
</code>. If the character has its meta bit (
0x80) set, the meta
bit is stripped, the preceding rules applied, and
"<tt class="character
">!</tt>" prepended to the result.
<dl><dt><b><tt id='l2h-
2174' xml:id='l2h-
2174'
>controlnames
</tt></b></dt>
A
33-element string array that contains the ASCII mnemonics for the
thirty-two ASCII control characters from
0 (NUL) to
0x1f (US), in
order, plus the mnemonic
"<tt class="samp
">SP</tt>" for the space character.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.17 curses.wrapper "
href=
"module-curses.wrapper.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6. Generic Operating System"
href=
"allos.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.19 curses.panel "
href=
"module-curses.panel.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-curses.wrapper.html">6.17 curses.wrapper
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"allos.html">6. Generic Operating System
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-curses.panel.html">6.19 curses.panel
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.