<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title>curses.ascii — Utilities for ASCII characters — Python 3.7.10 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/language_data.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.7.10 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="curses.panel — A panel stack extension for curses" href="curses.panel.html" /> <link rel="prev" title="curses — Terminal handling for character-cell displays" href="curses.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/curses.ascii.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> <style> @media only screen { table.full-width-table { width: 100%; } } </style> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="curses.panel.html" title="curses.panel — A panel stack extension for curses" accesskey="N">next</a> |</li> <li class="right" > <a href="curses.html" title="curses — Terminal handling for character-cell displays" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.7.10 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="allos.html" accesskey="U">Generic Operating System Services</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-curses.ascii"> <span id="curses-ascii-utilities-for-ascii-characters"></span><h1><a class="reference internal" href="#module-curses.ascii" title="curses.ascii: Constants and set-membership functions for ASCII characters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses.ascii</span></code></a> — Utilities for ASCII characters<a class="headerlink" href="#module-curses.ascii" title="Permalink to this headline">¶</a></h1> <hr class="docutils" /> <p>The <a class="reference internal" href="#module-curses.ascii" title="curses.ascii: Constants and set-membership functions for ASCII characters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses.ascii</span></code></a> 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:</p> <table class="docutils align-default"> <colgroup> <col style="width: 23%" /> <col style="width: 77%" /> </colgroup> <thead> <tr class="row-odd"><th class="head"><p>Name</p></th> <th class="head"><p>Meaning</p></th> </tr> </thead> <tbody> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">NUL</span></code></p></td> <td></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">SOH</span></code></p></td> <td><p>Start of heading, console interrupt</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">STX</span></code></p></td> <td><p>Start of text</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">ETX</span></code></p></td> <td><p>End of text</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EOT</span></code></p></td> <td><p>End of transmission</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">ENQ</span></code></p></td> <td><p>Enquiry, goes with <code class="xref py py-const docutils literal notranslate"><span class="pre">ACK</span></code> flow control</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">ACK</span></code></p></td> <td><p>Acknowledgement</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">BEL</span></code></p></td> <td><p>Bell</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">BS</span></code></p></td> <td><p>Backspace</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">TAB</span></code></p></td> <td><p>Tab</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">HT</span></code></p></td> <td><p>Alias for <code class="xref py py-const docutils literal notranslate"><span class="pre">TAB</span></code>: “Horizontal tab”</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">LF</span></code></p></td> <td><p>Line feed</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">NL</span></code></p></td> <td><p>Alias for <code class="xref py py-const docutils literal notranslate"><span class="pre">LF</span></code>: “New line”</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">VT</span></code></p></td> <td><p>Vertical tab</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">FF</span></code></p></td> <td><p>Form feed</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">CR</span></code></p></td> <td><p>Carriage return</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">SO</span></code></p></td> <td><p>Shift-out, begin alternate character set</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">SI</span></code></p></td> <td><p>Shift-in, resume default character set</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">DLE</span></code></p></td> <td><p>Data-link escape</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">DC1</span></code></p></td> <td><p>XON, for flow control</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">DC2</span></code></p></td> <td><p>Device control 2, block-mode flow control</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">DC3</span></code></p></td> <td><p>XOFF, for flow control</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">DC4</span></code></p></td> <td><p>Device control 4</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">NAK</span></code></p></td> <td><p>Negative acknowledgement</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">SYN</span></code></p></td> <td><p>Synchronous idle</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">ETB</span></code></p></td> <td><p>End transmission block</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">CAN</span></code></p></td> <td><p>Cancel</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">EM</span></code></p></td> <td><p>End of medium</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">SUB</span></code></p></td> <td><p>Substitute</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">ESC</span></code></p></td> <td><p>Escape</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">FS</span></code></p></td> <td><p>File separator</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">GS</span></code></p></td> <td><p>Group separator</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">RS</span></code></p></td> <td><p>Record separator, block-mode terminator</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">US</span></code></p></td> <td><p>Unit separator</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">SP</span></code></p></td> <td><p>Space</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">DEL</span></code></p></td> <td><p>Delete</p></td> </tr> </tbody> </table> <p>Note that many of these have little practical significance in modern usage. The mnemonics derive from teleprinter conventions that predate digital computers.</p> <p>The module supplies the following functions, patterned on those in the standard C library:</p> <dl class="function"> <dt id="curses.ascii.isalnum"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isalnum</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isalnum" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII alphanumeric character; it is equivalent to <code class="docutils literal notranslate"><span class="pre">isalpha(c)</span> <span class="pre">or</span> <span class="pre">isdigit(c)</span></code>.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isalpha"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isalpha</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isalpha" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII alphabetic character; it is equivalent to <code class="docutils literal notranslate"><span class="pre">isupper(c)</span> <span class="pre">or</span> <span class="pre">islower(c)</span></code>.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isascii"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isascii</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isascii" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for a character value that fits in the 7-bit ASCII set.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isblank"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isblank</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isblank" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII whitespace character; space or horizontal tab.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.iscntrl"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">iscntrl</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.iscntrl" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII control character (in the range 0x00 to 0x1f or 0x7f).</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isdigit"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isdigit</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isdigit" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII decimal digit, <code class="docutils literal notranslate"><span class="pre">'0'</span></code> through <code class="docutils literal notranslate"><span class="pre">'9'</span></code>. This is equivalent to <code class="docutils literal notranslate"><span class="pre">c</span> <span class="pre">in</span> <span class="pre">string.digits</span></code>.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isgraph"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isgraph</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isgraph" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for ASCII any printable character except space.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.islower"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">islower</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.islower" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII lower-case character.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isprint"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isprint</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isprint" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for any ASCII printable character including space.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.ispunct"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">ispunct</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.ispunct" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for any printable ASCII character which is not a space or an alphanumeric character.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isspace"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isspace</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isspace" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for ASCII white-space characters; space, line feed, carriage return, form feed, horizontal tab, vertical tab.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isupper"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isupper</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isupper" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII uppercase letter.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isxdigit"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isxdigit</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isxdigit" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII hexadecimal digit. This is equivalent to <code class="docutils literal notranslate"><span class="pre">c</span> <span class="pre">in</span> <span class="pre">string.hexdigits</span></code>.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.isctrl"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">isctrl</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.isctrl" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for an ASCII control character (ordinal values 0 to 31).</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.ismeta"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">ismeta</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.ismeta" title="Permalink to this definition">¶</a></dt> <dd><p>Checks for a non-ASCII character (ordinal values 0x80 and above).</p> </dd></dl> <p>These functions accept either integers or single-character strings; when the argument is a string, it is first converted using the built-in function <a class="reference internal" href="functions.html#ord" title="ord"><code class="xref py py-func docutils literal notranslate"><span class="pre">ord()</span></code></a>.</p> <p>Note that all these functions check ordinal bit values derived from the character of the string you pass in; they do not actually know anything about the host machine’s character encoding.</p> <p>The following two functions take either a single-character string or integer byte value; they return a value of the same type.</p> <dl class="function"> <dt id="curses.ascii.ascii"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">ascii</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.ascii" title="Permalink to this definition">¶</a></dt> <dd><p>Return the ASCII value corresponding to the low 7 bits of <em>c</em>.</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.ctrl"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">ctrl</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.ctrl" title="Permalink to this definition">¶</a></dt> <dd><p>Return the control character corresponding to the given character (the character bit value is bitwise-anded with 0x1f).</p> </dd></dl> <dl class="function"> <dt id="curses.ascii.alt"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">alt</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.alt" title="Permalink to this definition">¶</a></dt> <dd><p>Return the 8-bit character corresponding to the given ASCII character (the character bit value is bitwise-ored with 0x80).</p> </dd></dl> <p>The following function takes either a single-character string or integer value; it returns a string.</p> <span class="target" id="index-0"></span><dl class="function"> <dt id="curses.ascii.unctrl"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">unctrl</code><span class="sig-paren">(</span><em class="sig-param">c</em><span class="sig-paren">)</span><a class="headerlink" href="#curses.ascii.unctrl" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string representation of the ASCII character <em>c</em>. If <em>c</em> is printable, this string is the character itself. If the character is a control character (0x00–0x1f) the string consists of a caret (<code class="docutils literal notranslate"><span class="pre">'^'</span></code>) followed by the corresponding uppercase letter. If the character is an ASCII delete (0x7f) the string is <code class="docutils literal notranslate"><span class="pre">'^?'</span></code>. If the character has its meta bit (0x80) set, the meta bit is stripped, the preceding rules applied, and <code class="docutils literal notranslate"><span class="pre">'!'</span></code> prepended to the result.</p> </dd></dl> <dl class="data"> <dt id="curses.ascii.controlnames"> <code class="sig-prename descclassname">curses.ascii.</code><code class="sig-name descname">controlnames</code><a class="headerlink" href="#curses.ascii.controlnames" title="Permalink to this definition">¶</a></dt> <dd><p>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 <code class="docutils literal notranslate"><span class="pre">SP</span></code> for the space character.</p> </dd></dl> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="curses.html" title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses</span></code> — Terminal handling for character-cell displays</a></p> <h4>Next topic</h4> <p class="topless"><a href="curses.panel.html" title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses.panel</span></code> — A panel stack extension for curses</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.7/Doc/library/curses.ascii.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="curses.panel.html" title="curses.panel — A panel stack extension for curses" >next</a> |</li> <li class="right" > <a href="curses.html" title="curses — Terminal handling for character-cell displays" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.7.10 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="allos.html" >Generic Operating System Services</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2021, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Feb 26, 2021. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.3.1. </div> </body> </html>