python curses.ascii 取决于语言环境?
curses.ascii 模块定义了一些不错的函数,例如可以识别哪些字符是可打印的 (curses.ascii.isprint(ch))。
但是,根据使用的区域设置,可以打印不同的字符代码。 例如,有某些波兰语字符:
>>> ord('a')
97
>>> ord('ą')
177
>>>
我想知道,是否有更好的方法来判断数字是否代表可打印字符,然后在 curses.ascii
模块中使用:
def isprint(c): return _ctoi(c) >= 32 and _ctoi(c) <= 126
这是一种语言环境 -不友好。
The curses.ascii
module has some nice functions defined, that allow for example to recognize which characters are printable (curses.ascii.isprint(ch)
).
But, diffrent character codes can be printable depending on which locale setting is being used. For example, there are certain polish characters:
>>> ord('a')
97
>>> ord('ą')
177
>>>
I'm wondering, is there a better way to tell if a number represents printable character then the one used in curses.ascii
module:
def isprint(c): return _ctoi(c) >= 32 and _ctoi(c) <= 126
which is kind of locale-unfriendly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将字符转换为 unicode,则可以使用 unicodedata:
If you convert the character to a unicode then you can use unicodedata:
嗯,它被称为curses.ascii,所以对可打印的内容使用ASCII 规则应该不足为奇。 如果您使用 ISO 8 位代码,或者从已知代码页进行操作,则需要与实际代码及其显示相对应的规则。
我认为使用 unicode 字符和标准 Unicode 分类就可以了。 这可能无法解决诅咒和控制台安排实际要正确显示的内容。
即使可以显示,还需要考虑应用程序可接受和不可接受的内容。
Well, it is called curses.ascii, so using ASCII rules for what's printable should not be a surprise. If you are using an ISO 8-bit code, or you are operating from a known code page, you will need rules that correspond to what the actual codes and their displays are.
I think using unicode characters and standard Unicode classifications is fine. That just might not deal with what the curses and console arrangement are actually going to display properly.
There also needs to be some consideration for what is acceptable and unacceptable for the application, even if displayable.