Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-curses.panel.html" /> | |
13 | <link rel="prev" href="module-curses.wrapper.html" /> | |
14 | <link rel="parent" href="allos.html" /> | |
15 | <link rel="next" href="module-curses.panel.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.18 curses.ascii -- Utilities for ASCII characters</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6.17 curses.wrapper " | |
25 | href="module-curses.wrapper.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
28 | href="allos.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.19 curses.panel " | |
31 | href="module-curses.panel.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-curses.wrapper.html">6.17 curses.wrapper </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-curses.panel.html">6.19 curses.panel </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0081800000000000000000"> | |
56 | 6.18 <tt class="module">curses.ascii</tt> -- | |
57 | Utilities for ASCII characters</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-curses.ascii"></A> | |
62 | ||
63 | <P> | |
64 | ||
65 | <span class="versionnote">New in version 1.6.</span> | |
66 | ||
67 | <P> | |
68 | The <tt class="module">curses.ascii</tt> module supplies name constants for | |
69 | ASCII characters and functions to test membership in various | |
70 | ASCII character classes. The constants supplied are names for | |
71 | control characters as follows: | |
72 | ||
73 | <P> | |
74 | <div class="center"><table class="realtable"> | |
75 | <thead> | |
76 | <tr> | |
77 | <th class="left" >Name</th> | |
78 | <th class="left" >Meaning</th> | |
79 | </tr> | |
80 | </thead> | |
81 | <tbody> | |
82 | <tr><td class="left" valign="baseline"><tt class="constant">NUL</tt></td> | |
83 | <td class="left" ></td></tr> | |
84 | <tr><td class="left" valign="baseline"><tt class="constant">SOH</tt></td> | |
85 | <td class="left" >Start of heading, console interrupt</td></tr> | |
86 | <tr><td class="left" valign="baseline"><tt class="constant">STX</tt></td> | |
87 | <td class="left" >Start of text</td></tr> | |
88 | <tr><td class="left" valign="baseline"><tt class="constant">ETX</tt></td> | |
89 | <td class="left" >End of text</td></tr> | |
90 | <tr><td class="left" valign="baseline"><tt class="constant">EOT</tt></td> | |
91 | <td class="left" >End of transmission</td></tr> | |
92 | <tr><td class="left" valign="baseline"><tt class="constant">ENQ</tt></td> | |
93 | <td class="left" >Enquiry, goes with <tt class="constant">ACK</tt> flow control</td></tr> | |
94 | <tr><td class="left" valign="baseline"><tt class="constant">ACK</tt></td> | |
95 | <td class="left" >Acknowledgement</td></tr> | |
96 | <tr><td class="left" valign="baseline"><tt class="constant">BEL</tt></td> | |
97 | <td class="left" >Bell</td></tr> | |
98 | <tr><td class="left" valign="baseline"><tt class="constant">BS</tt></td> | |
99 | <td class="left" >Backspace</td></tr> | |
100 | <tr><td class="left" valign="baseline"><tt class="constant">TAB</tt></td> | |
101 | <td class="left" >Tab</td></tr> | |
102 | <tr><td class="left" valign="baseline"><tt class="constant">HT</tt></td> | |
103 | <td class="left" >Alias for <tt class="constant">TAB</tt>: ``Horizontal tab''</td></tr> | |
104 | <tr><td class="left" valign="baseline"><tt class="constant">LF</tt></td> | |
105 | <td class="left" >Line feed</td></tr> | |
106 | <tr><td class="left" valign="baseline"><tt class="constant">NL</tt></td> | |
107 | <td class="left" >Alias for <tt class="constant">LF</tt>: ``New line''</td></tr> | |
108 | <tr><td class="left" valign="baseline"><tt class="constant">VT</tt></td> | |
109 | <td class="left" >Vertical tab</td></tr> | |
110 | <tr><td class="left" valign="baseline"><tt class="constant">FF</tt></td> | |
111 | <td class="left" >Form feed</td></tr> | |
112 | <tr><td class="left" valign="baseline"><tt class="constant">CR</tt></td> | |
113 | <td class="left" >Carriage return</td></tr> | |
114 | <tr><td class="left" valign="baseline"><tt class="constant">SO</tt></td> | |
115 | <td class="left" >Shift-out, begin alternate character set</td></tr> | |
116 | <tr><td class="left" valign="baseline"><tt class="constant">SI</tt></td> | |
117 | <td class="left" >Shift-in, resume default character set</td></tr> | |
118 | <tr><td class="left" valign="baseline"><tt class="constant">DLE</tt></td> | |
119 | <td class="left" >Data-link escape</td></tr> | |
120 | <tr><td class="left" valign="baseline"><tt class="constant">DC1</tt></td> | |
121 | <td class="left" >XON, for flow control</td></tr> | |
122 | <tr><td class="left" valign="baseline"><tt class="constant">DC2</tt></td> | |
123 | <td class="left" >Device control 2, block-mode flow control</td></tr> | |
124 | <tr><td class="left" valign="baseline"><tt class="constant">DC3</tt></td> | |
125 | <td class="left" >XOFF, for flow control</td></tr> | |
126 | <tr><td class="left" valign="baseline"><tt class="constant">DC4</tt></td> | |
127 | <td class="left" >Device control 4</td></tr> | |
128 | <tr><td class="left" valign="baseline"><tt class="constant">NAK</tt></td> | |
129 | <td class="left" >Negative acknowledgement</td></tr> | |
130 | <tr><td class="left" valign="baseline"><tt class="constant">SYN</tt></td> | |
131 | <td class="left" >Synchronous idle</td></tr> | |
132 | <tr><td class="left" valign="baseline"><tt class="constant">ETB</tt></td> | |
133 | <td class="left" >End transmission block</td></tr> | |
134 | <tr><td class="left" valign="baseline"><tt class="constant">CAN</tt></td> | |
135 | <td class="left" >Cancel</td></tr> | |
136 | <tr><td class="left" valign="baseline"><tt class="constant">EM</tt></td> | |
137 | <td class="left" >End of medium</td></tr> | |
138 | <tr><td class="left" valign="baseline"><tt class="constant">SUB</tt></td> | |
139 | <td class="left" >Substitute</td></tr> | |
140 | <tr><td class="left" valign="baseline"><tt class="constant">ESC</tt></td> | |
141 | <td class="left" >Escape</td></tr> | |
142 | <tr><td class="left" valign="baseline"><tt class="constant">FS</tt></td> | |
143 | <td class="left" >File separator</td></tr> | |
144 | <tr><td class="left" valign="baseline"><tt class="constant">GS</tt></td> | |
145 | <td class="left" >Group separator</td></tr> | |
146 | <tr><td class="left" valign="baseline"><tt class="constant">RS</tt></td> | |
147 | <td class="left" >Record separator, block-mode terminator</td></tr> | |
148 | <tr><td class="left" valign="baseline"><tt class="constant">US</tt></td> | |
149 | <td class="left" >Unit separator</td></tr> | |
150 | <tr><td class="left" valign="baseline"><tt class="constant">SP</tt></td> | |
151 | <td class="left" >Space</td></tr> | |
152 | <tr><td class="left" valign="baseline"><tt class="constant">DEL</tt></td> | |
153 | <td class="left" >Delete</td></tr></tbody> | |
154 | </table></div> | |
155 | ||
156 | <P> | |
157 | Note that many of these have little practical significance in modern | |
158 | usage. The mnemonics derive from teleprinter conventions that predate | |
159 | digital computers. | |
160 | ||
161 | <P> | |
162 | The module supplies the following functions, patterned on those in the | |
163 | standard C library: | |
164 | ||
165 | <P> | |
166 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
167 | <td><nobr><b><tt id='l2h-2155' xml:id='l2h-2155' class="function">isalnum</tt></b>(</nobr></td> | |
168 | <td><var>c</var>)</td></tr></table></dt> | |
169 | <dd> | |
170 | Checks for an ASCII alphanumeric character; it is equivalent to | |
171 | "<tt class="samp">isalpha(<var>c</var>) or isdigit(<var>c</var>)</tt>". | |
172 | </dl> | |
173 | ||
174 | <P> | |
175 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
176 | <td><nobr><b><tt id='l2h-2156' xml:id='l2h-2156' class="function">isalpha</tt></b>(</nobr></td> | |
177 | <td><var>c</var>)</td></tr></table></dt> | |
178 | <dd> | |
179 | Checks for an ASCII alphabetic character; it is equivalent to | |
180 | "<tt class="samp">isupper(<var>c</var>) or islower(<var>c</var>)</tt>". | |
181 | </dl> | |
182 | ||
183 | <P> | |
184 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
185 | <td><nobr><b><tt id='l2h-2157' xml:id='l2h-2157' class="function">isascii</tt></b>(</nobr></td> | |
186 | <td><var>c</var>)</td></tr></table></dt> | |
187 | <dd> | |
188 | Checks for a character value that fits in the 7-bit ASCII set. | |
189 | </dl> | |
190 | ||
191 | <P> | |
192 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
193 | <td><nobr><b><tt id='l2h-2158' xml:id='l2h-2158' class="function">isblank</tt></b>(</nobr></td> | |
194 | <td><var>c</var>)</td></tr></table></dt> | |
195 | <dd> | |
196 | Checks for an ASCII whitespace character. | |
197 | </dl> | |
198 | ||
199 | <P> | |
200 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
201 | <td><nobr><b><tt id='l2h-2159' xml:id='l2h-2159' class="function">iscntrl</tt></b>(</nobr></td> | |
202 | <td><var>c</var>)</td></tr></table></dt> | |
203 | <dd> | |
204 | Checks for an ASCII control character (in the range 0x00 to 0x1f). | |
205 | </dl> | |
206 | ||
207 | <P> | |
208 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
209 | <td><nobr><b><tt id='l2h-2160' xml:id='l2h-2160' class="function">isdigit</tt></b>(</nobr></td> | |
210 | <td><var>c</var>)</td></tr></table></dt> | |
211 | <dd> | |
212 | Checks for an ASCII decimal digit, "<tt class="character">0</tt>" through | |
213 | "<tt class="character">9</tt>". This is equivalent to "<tt class="samp"><var>c</var> in string.digits</tt>". | |
214 | </dl> | |
215 | ||
216 | <P> | |
217 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
218 | <td><nobr><b><tt id='l2h-2161' xml:id='l2h-2161' class="function">isgraph</tt></b>(</nobr></td> | |
219 | <td><var>c</var>)</td></tr></table></dt> | |
220 | <dd> | |
221 | Checks for ASCII any printable character except space. | |
222 | </dl> | |
223 | ||
224 | <P> | |
225 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
226 | <td><nobr><b><tt id='l2h-2162' xml:id='l2h-2162' class="function">islower</tt></b>(</nobr></td> | |
227 | <td><var>c</var>)</td></tr></table></dt> | |
228 | <dd> | |
229 | Checks for an ASCII lower-case character. | |
230 | </dl> | |
231 | ||
232 | <P> | |
233 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
234 | <td><nobr><b><tt id='l2h-2163' xml:id='l2h-2163' class="function">isprint</tt></b>(</nobr></td> | |
235 | <td><var>c</var>)</td></tr></table></dt> | |
236 | <dd> | |
237 | Checks for any ASCII printable character including space. | |
238 | </dl> | |
239 | ||
240 | <P> | |
241 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
242 | <td><nobr><b><tt id='l2h-2164' xml:id='l2h-2164' class="function">ispunct</tt></b>(</nobr></td> | |
243 | <td><var>c</var>)</td></tr></table></dt> | |
244 | <dd> | |
245 | Checks for any printable ASCII character which is not a space or an | |
246 | alphanumeric character. | |
247 | </dl> | |
248 | ||
249 | <P> | |
250 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
251 | <td><nobr><b><tt id='l2h-2165' xml:id='l2h-2165' class="function">isspace</tt></b>(</nobr></td> | |
252 | <td><var>c</var>)</td></tr></table></dt> | |
253 | <dd> | |
254 | Checks for ASCII white-space characters; space, line feed, | |
255 | carriage return, form feed, horizontal tab, vertical tab. | |
256 | </dl> | |
257 | ||
258 | <P> | |
259 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
260 | <td><nobr><b><tt id='l2h-2166' xml:id='l2h-2166' class="function">isupper</tt></b>(</nobr></td> | |
261 | <td><var>c</var>)</td></tr></table></dt> | |
262 | <dd> | |
263 | Checks for an ASCII uppercase letter. | |
264 | </dl> | |
265 | ||
266 | <P> | |
267 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
268 | <td><nobr><b><tt id='l2h-2167' xml:id='l2h-2167' class="function">isxdigit</tt></b>(</nobr></td> | |
269 | <td><var>c</var>)</td></tr></table></dt> | |
270 | <dd> | |
271 | Checks for an ASCII hexadecimal digit. This is equivalent to | |
272 | "<tt class="samp"><var>c</var> in string.hexdigits</tt>". | |
273 | </dl> | |
274 | ||
275 | <P> | |
276 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
277 | <td><nobr><b><tt id='l2h-2168' xml:id='l2h-2168' class="function">isctrl</tt></b>(</nobr></td> | |
278 | <td><var>c</var>)</td></tr></table></dt> | |
279 | <dd> | |
280 | Checks for an ASCII control character (ordinal values 0 to 31). | |
281 | </dl> | |
282 | ||
283 | <P> | |
284 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
285 | <td><nobr><b><tt id='l2h-2169' xml:id='l2h-2169' class="function">ismeta</tt></b>(</nobr></td> | |
286 | <td><var>c</var>)</td></tr></table></dt> | |
287 | <dd> | |
288 | Checks for a non-ASCII character (ordinal values 0x80 and above). | |
289 | </dl> | |
290 | ||
291 | <P> | |
292 | These functions accept either integers or strings; when the argument | |
293 | is a string, it is first converted using the built-in function | |
294 | <tt class="function">ord()</tt>. | |
295 | ||
296 | <P> | |
297 | Note that all these functions check ordinal bit values derived from the | |
298 | first character of the string you pass in; they do not actually know | |
299 | anything about the host machine's character encoding. For functions | |
300 | that know about the character encoding (and handle | |
301 | internationalization properly) see the <tt class="module"><a href="module-string.html">string</a></tt> module. | |
302 | ||
303 | <P> | |
304 | The following two functions take either a single-character string or | |
305 | integer byte value; they return a value of the same type. | |
306 | ||
307 | <P> | |
308 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
309 | <td><nobr><b><tt id='l2h-2170' xml:id='l2h-2170' class="function">ascii</tt></b>(</nobr></td> | |
310 | <td><var>c</var>)</td></tr></table></dt> | |
311 | <dd> | |
312 | Return the ASCII value corresponding to the low 7 bits of <var>c</var>. | |
313 | </dl> | |
314 | ||
315 | <P> | |
316 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
317 | <td><nobr><b><tt id='l2h-2171' xml:id='l2h-2171' class="function">ctrl</tt></b>(</nobr></td> | |
318 | <td><var>c</var>)</td></tr></table></dt> | |
319 | <dd> | |
320 | Return the control character corresponding to the given character | |
321 | (the character bit value is bitwise-anded with 0x1f). | |
322 | </dl> | |
323 | ||
324 | <P> | |
325 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
326 | <td><nobr><b><tt id='l2h-2172' xml:id='l2h-2172' class="function">alt</tt></b>(</nobr></td> | |
327 | <td><var>c</var>)</td></tr></table></dt> | |
328 | <dd> | |
329 | Return the 8-bit character corresponding to the given ASCII character | |
330 | (the character bit value is bitwise-ored with 0x80). | |
331 | </dl> | |
332 | ||
333 | <P> | |
334 | The following function takes either a single-character string or | |
335 | integer value; it returns a string. | |
336 | ||
337 | <P> | |
338 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
339 | <td><nobr><b><tt id='l2h-2173' xml:id='l2h-2173' class="function">unctrl</tt></b>(</nobr></td> | |
340 | <td><var>c</var>)</td></tr></table></dt> | |
341 | <dd> | |
342 | Return a string representation of the ASCII character <var>c</var>. If | |
343 | <var>c</var> is printable, this string is the character itself. If the | |
344 | character is a control character (0x00-0x1f) the string consists of a | |
345 | caret ("<tt class="character">^</tt>") followed by the corresponding uppercase letter. | |
346 | If the character is an ASCII delete (0x7f) the string is | |
347 | <code>'^?'</code>. If the character has its meta bit (0x80) set, the meta | |
348 | bit is stripped, the preceding rules applied, and | |
349 | "<tt class="character">!</tt>" prepended to the result. | |
350 | </dl> | |
351 | ||
352 | <P> | |
353 | <dl><dt><b><tt id='l2h-2174' xml:id='l2h-2174'>controlnames</tt></b></dt> | |
354 | <dd> | |
355 | A 33-element string array that contains the ASCII mnemonics for the | |
356 | thirty-two ASCII control characters from 0 (NUL) to 0x1f (US), in | |
357 | order, plus the mnemonic "<tt class="samp">SP</tt>" for the space character. | |
358 | </dd></dl> | |
359 | ||
360 | <DIV CLASS="navigation"> | |
361 | <div class='online-navigation'> | |
362 | <p></p><hr /> | |
363 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
364 | <tr> | |
365 | <td class='online-navigation'><a rel="prev" title="6.17 curses.wrapper " | |
366 | href="module-curses.wrapper.html"><img src='../icons/previous.png' | |
367 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
368 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
369 | href="allos.html"><img src='../icons/up.png' | |
370 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
371 | <td class='online-navigation'><a rel="next" title="6.19 curses.panel " | |
372 | href="module-curses.panel.html"><img src='../icons/next.png' | |
373 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
374 | <td align="center" width="100%">Python Library Reference</td> | |
375 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
376 | href="contents.html"><img src='../icons/contents.png' | |
377 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
378 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
379 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
380 | <td class='online-navigation'><a rel="index" title="Index" | |
381 | href="genindex.html"><img src='../icons/index.png' | |
382 | border='0' height='32' alt='Index' width='32' /></A></td> | |
383 | </tr></table> | |
384 | <div class='online-navigation'> | |
385 | <b class="navlabel">Previous:</b> | |
386 | <a class="sectref" rel="prev" href="module-curses.wrapper.html">6.17 curses.wrapper </A> | |
387 | <b class="navlabel">Up:</b> | |
388 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
389 | <b class="navlabel">Next:</b> | |
390 | <a class="sectref" rel="next" href="module-curses.panel.html">6.19 curses.panel </A> | |
391 | </div> | |
392 | </div> | |
393 | <hr /> | |
394 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
395 | </DIV> | |
396 | <!--End of Navigation Panel--> | |
397 | <ADDRESS> | |
398 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
399 | </ADDRESS> | |
400 | </BODY> | |
401 | </HTML> |