Python curses.ascii depending on the language?

The module curses.ascii

has several useful functions that allow, for example, to recognize which characters can be printed ( curses.ascii.isprint(ch)

).

But different character codes can be printed depending on which language is used. For example, there are some Polish characters:

>>> ord('a')
97
>>> ord('ą')
177
>>> 

      

I'm wondering if there is a better way to find out if a number represents the print character that is used in a module curses.ascii

:

def isprint(c): return _ctoi(c) >= 32 and _ctoi(c) <= 126

      

which is kind of local unfriendly.

0


source to share


2 answers


If you are converting a character to unicode, you can use unicodedata:



>>> unicodedata.category(u'ą')[0] in 'LNPS'
True

      

+4


source


Well, it's called curses.ascii, so using ASCII rules for printing shouldn't come as a surprise. If you are using 8-bit ISO code, or are running on a known code page, you will need rules that match the actual codes and their displays.

I think the use of Unicode characters and standard Unicode classifications is fine. It just can't deal with what swear words and consoles will actually display.



You also need to consider what is acceptable and unacceptable for the application, even if it is displayed.

+2


source







All Articles