Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex

14.10curses.ascii -- Utilities for ASCII characters

New in version 1.6.

Thecurses.ascii module supplies name constants forASCII characters and functions to test membership in variousASCII character classes. The constants supplied are names forcontrol characters as follows:

NameMeaning
NUL
SOHStart of heading, console interrupt
STXStart of text
ETXEnd of text
EOTEnd of transmission
ENQEnquiry, goes withACK flow control
ACKAcknowledgement
BELBell
BSBackspace
TABTab
HTAlias forTAB: ``Horizontal tab''
LFLine feed
NLAlias forLF: ``New line''
VTVertical tab
FFForm feed
CRCarriage return
SOShift-out, begin alternate character set
SIShift-in, resume default character set
DLEData-link escape
DC1XON, for flow control
DC2Device control 2, block-mode flow control
DC3XOFF, for flow control
DC4Device control 4
NAKNegative acknowledgement
SYNSynchronous idle
ETBEnd transmission block
CANCancel
EMEnd of medium
SUBSubstitute
ESCEscape
FSFile separator
GSGroup separator
RSRecord separator, block-mode terminator
USUnit separator
SPSpace
DELDelete

Note that many of these have little practical significance in modernusage. The mnemonics derive from teleprinter conventions that predatedigital computers.

The module supplies the following functions, patterned on those in thestandard C library:

isalnum(c)
Checks for an ASCII alphanumeric character; it is equivalent to"isalpha(c) or isdigit(c)".

isalpha(c)
Checks for an ASCII alphabetic character; it is equivalent to"isupper(c) or islower(c)".

isascii(c)
Checks for a character value that fits in the 7-bit ASCII set.

isblank(c)
Checks for an ASCII whitespace character.

iscntrl(c)
Checks for an ASCII control character (in the range 0x00 to 0x1f).

isdigit(c)
Checks for an ASCII decimal digit, "0" through"9". This is equivalent to "c in string.digits".

isgraph(c)
Checks for ASCII any printable character except space.

islower(c)
Checks for an ASCII lower-case character.

isprint(c)
Checks for any ASCII printable character including space.

ispunct(c)
Checks for any printable ASCII character which is not a space or analphanumeric character.

isspace(c)
Checks for ASCII white-space characters; space, line feed,carriage return, form feed, horizontal tab, vertical tab.

isupper(c)
Checks for an ASCII uppercase letter.

isxdigit(c)
Checks for an ASCII hexadecimal digit. This is equivalent to"c in string.hexdigits".

isctrl(c)
Checks for an ASCII control character (ordinal values 0 to 31).

ismeta(c)
Checks for a non-ASCII character (ordinal values 0x80 and above).

These functions accept either integers or strings; when the argumentis a string, it is first converted using the built-in functionord().

Note that all these functions check ordinal bit values derived from the first character of the string you pass in; they do not actually knowanything about the host machine's character encoding. For functions that know about the character encoding (and handleinternationalization properly) see thestring module.

The following two functions take either a single-character string orinteger byte value; they return a value of the same type.

ascii(c)
Return the ASCII value corresponding to the low 7 bits ofc.

ctrl(c)
Return the control character corresponding to the given character(the character bit value is bitwise-anded with 0x1f).

alt(c)
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 orinteger value; it returns a string.

unctrl(c)
Return a string representation of the ASCII characterc. Ifc is printable, this string is the character itself. If thecharacter is a control character (0x00-0x1f) the string consists of acaret ("^") followed by the corresponding uppercase letter.If the character is an ASCII delete (0x7f) the string is'^?'. If the character has its meta bit (0x80) set, the metabit is stripped, the preceding rules applied, and"!" prepended to the result.

controlnames
A 33-element string array that contains the ASCII mnemonics for thethirty-two ASCII control characters from 0 (NUL) to 0x1f (US), inorder, plus the mnemonic "SP" for the space character.


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp