这可能是一个愚蠢的问题,但我不明白string模块中的string.uppercase和string.ascii_uppercase有什么不同。打印这两个函数的docstring将打印相同的内容。甚至print string.uppercase和print string.ascii_uppercase的输出也是相同的。
谢谢。
发布于 2011-02-09 15:15:39
请参阅:http://docs.python.org/library/string.html
string.ascii_uppercase:
string.uppercase:
发布于 2011-02-09 18:05:00
请注意,在Python3.x中,string.uppercase以及string.lowercase和string.letters都被蒸发了。当您更改语言环境时,全局“常量”会发生变化,这被认为是不好的做法。(参见http://docs.python.org/py3k/whatsnew/3.0.html)
因此,对于任何新代码来说,最好的办法可能就是假装它们也不存在于Python2.x中。这样,即使您需要迁移到Python 3.x,也不会存储问题
发布于 2016-02-11 09:40:39
在没有string.uppercase或string.ascii_uppercase的Python3.x上,可以通过使用regex包中的[:upper:]获得类似的功能,并添加regex.UNICODE以使其更像string.uppercase,即任何语言的大写字符(即不仅是当前语言环境)。
https://stackoverflow.com/questions/4942239
复制相似问题