On 3/05/2006 12:44 AM, Dean Allen Provins wrote: > Roger Upole wrote: >> Bill Burns wrote: >> >>>> On 2/05/2006 8:16 AM, Dean Allen Provins wrote: >>>> >>>> >>>>> Hello: >>>>> >>>>> I just installed the 2.4 version of Python on a WinXP box. I then >>>>> copied over my python code which runs under Linux. This code uses >>>>> "curses.ascii" (isspace specifically). >>>>> >>>>> The Win version of the libraries has a curses directory and within it, >>>>> the ascii.py module. Unfortunately, the __init__.py module in the >>>>> curses directory expects to import "_curses" (as it does on Linux), and >>>>> this is nowhere to be found in the Windows python install directory (it >>>>> is part of a shared library under Linux). >>>>> >>>>> To get around the problem, I simply commented out the entire __init__.py >>>>> module, but this provides only symptomatic relief. >>>>> >>>>> Any readers know why the "_curses" library is missing, or in other >>>>> words, have I found an "error of omission"? >>>>> >>>> >>>> http://www.amk.ca/python/howto/curses/ >>>> >>>> "Nobody has made a Windows port" or words to that effect ... >>> Actually, I just found this.... but I've never tried it >>> >>> http://adamv.com/dev/python/curses/ >>> >>> but I believe John is partial right ;-), in the sense that, the Standard >>> Python distribution doesn't supply curses for Windows. >>> >>> So you have *not* found an "error of omission". >>> >>> Google "Windows _curses" on comp.lang.python for more info and other >>> possibilities. >>> >>> Bill >> >> Newer versions of Pywin32 come with a win32console module that >> allows you to create and interact with console windows. >> >> Roger > > John. Bill and Roger: > > Thanks for your responses. > > Fortunately, I don't need anything from the curses library except the > "isspace" function in "curses.ascii". Since the module "_curses" isn't > available in the WIN version, I've decided to copy the "ascii.py" module > over to my collection of codes and transfer it to Windows, rather than > try to import a surgically-altered version of the curses module > (described above). This should simplify the installation on other WIN > machines. >
From curses/ascii.py: def isspace(c): return _ctoi(c) in (9, 10, 11, 12, 13, 32) Code reuse is great, but transporting and importing a whole irrelevant module to get a fugly ill-coded one-liner and a further unnecessary function call (_ctoi) qualifies for bogglement of the month [so far]. Try inserting this OS-independent one-liner in your code somewhere: def isspace(c): return c in (' ', '\t', '\n', '\r', '\f', '\v') It appears to work all the way back to Python 2.1 (see below). I could arc up the box with 1.5.2 on it and check it out for you if you truly rooly want a Python-version-agnostic function :-) C:\junk>\python21\python Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> def isspace(c): return c in (' ', '\t', '\n', '\r', '\f', '\v') ... >>> for x in (666, 1.23, 'a', 'z', 'fubar', ' ', '\t', '\n', '\r', '\f', '\v'): ... print repr(x), isspace(x) ... 666 0 1.23 0 'a' 0 'z' 0 'fubar' 0 ' ' 1 '\t' 1 '\n' 1 '\r' 1 '\x0c' 1 '\x0b' 1 >>> for x in (8, 9, 10, 11, 12, 13, 14, 31, 32, 33): ... print x, repr(chr(x)), isspace(chr(x)) ... 8 '\x08' 0 9 '\t' 1 10 '\n' 1 11 '\x0b' 1 12 '\x0c' 1 13 '\r' 1 14 '\x0e' 0 31 '\x1f' 0 32 ' ' 1 33 '!' 0 >>> HTH, John _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32