'Python: string.uppercase vs. string.ascii_uppercase
This might be a stupid question but I don't understand what's the difference between string.uppercase and string.ascii_uppercase in the string module. Printing the docstring of both the function prints same thing. Even the output of print string.uppercase and print string.ascii_uppercase is same.
Thanks.
Solution 1:[1]
Note that in Python 3.x string.uppercase and also string.lowercase and string.letters have vapourised. It was not considered good practice to have global 'constants' that varied when you changed locale. (See http://docs.python.org/py3k/whatsnew/3.0.html)
So the best thing for any new code is probably to pretend they don't exist in Python 2.x either. That way you don't store up problems if you ever do need to migrate to Python 3.x
Solution 2:[2]
On Python 3.x which doesnt have string.uppercase or string.ascii_uppercase, similar functionality can be obtained by using [:upper:] from the regex package, and add regex.UNICODE to be more like string.uppercase, i.e. uppercase characters any language (i.e. not only the current locale).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Duncan |
| Solution 2 |
