[Tutor] Curses

Jeff Shannon jeff@ccvcorp.com
Thu, 27 Jun 2002 09:26:43 -0700


Terje Johan Abrahamsen wrote:

> I need the module curses.ascii.isdigit ....

Are you *sure* that you need that??  ;)

>>> "123".isdigit()
1
>>> "A23".isdigit()
0
>>> "6fg".isdigit()
0
>>>

There is now a string method isdigit(), that's available anywhere (Python 2.0+,
IIRC).  The curses package, on the other hand, is a Unix-only thing.  There may
be some ports of curses for Win32, but they're not included in the standard
Python distribution.  Besides, the point of curses is to manipulate the terminal
-- if you simply need to find out information about a string, without affecting
the terminal itself, then you're much better off using the lighter-weight string
module, or better yet the built-in string methods.


> import curses
> from curses import ascii
> from curses.ascii import isdigit

By the way, if you *are* trying to import something from within a nested package
like this, the first two lines are unnecessary.  If you use "from curses.ascii
import isdigit", the interpreter will automatically import the higher levels for
you.  The only reason to use the first two lines, would be if you need access to
other items in, say, the curses.ascii namespace.  (In which case, though, you'd
be better off just using "from curses import ascii", and then
"ascii.isdigit(mystring)" or whatever.)

Jeff Shannon
Technician/Programmer
Credit International