[Python-Dev] ascii.py?
Eric S. Raymond
esr@thyrsus.com
Thu, 1 Jun 2000 18:51:45 -0400
Greg Stein <gstein@lyra.org>:
> I took a quick look at it. Doesn't seem too bad, but I can't think of
> anything that I've done in a long while that would require it. So I can't
> really say "wow! put that baby in the distro!"
It starts to get pretty useful in conjunction with curses -- for example, in
writing interpreters for character-at-a-time command loops.
I have a new version that adds the following:
\begin{funcdesc}{ascii}{c}
Return the ASCII value corresponding to the low 7 bits of c.
\end{funcdesc}
The following function takes either a single-character string or
integer byte value; it returns a string.
\begin{funcdesc}{unctrl}{c}
Return a string representation of the ASCII character c. If c is
printable, this string is the character itself. If the character
is a control character (0x00-0x1f) the string consists of a caret
(^) 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 meta bit is stripped, the preceding rules
applied, and "!" prepended to the result.
\end{funcdesc}
Finally, the module supplies a 33-element string array
called controlnames that contains the ASCII mnemonics for the
thirty-two ASCII control characters from 0 (NUL) to 0x1f (US),
in order, plus the mnemonic "SP" for space.
--
<a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a>
Certainly one of the chief guarantees of freedom under any government,
no matter how popular and respected, is the right of the citizens to
keep and bear arms. [...] the right of the citizens to bear arms is
just one guarantee against arbitrary government and one more safeguard
against a tyranny which now appears remote in America, but which
historically has proved to be always possible.
-- Hubert H. Humphrey, 1960