python curses.ascii 取决于语言环境?

发布于 2024-07-10 06:15:16 字数 404 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゃ懵逼小萝莉 2024-07-17 06:15:16

如果将字符转换为 unicode,则可以使用 unicodedata:

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

If you convert the character to a unicode then you can use unicodedata:

>>> unicodedata.category(u'ą')[0] in 'LNPS'
True
情未る 2024-07-17 06:15:16

嗯,它被称为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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文