-
-
Save mattboehm/98ae4871ae21821c21cb9f2aecbb9c39 to your computer and use it in GitHub Desktop.
Python 2.7.10 (default, Oct 23 2015, 19:19:21) | |
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import string | |
>>> string.letters | |
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
>>> help(string) | |
>>> string.letters | |
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' |
letters
is initially defined in string.py
as letters = lowercase + uppercase
. However, if your locale gets updated, then letters
gets redefined in _localemodule.c
to be a lexicographically ordered collection of characters for which isalpha(c)
is true. Uppercase letters have a lower ordinal value than lowercase, so they come first. This is briefly touched upon in the docs although not in that much detail.
I don't know how/if help()
is calling setlocale
, though.
3.X's ascii_letters
doesn't change, because it is not locale-dependent.
On ipython, it is already reversed the first time, and calling help on string doesn't change it. Tested on python 2.7.6, ubuntu 14.04, locale en_US UTF-8, ipython 5.1.0
@kms70847 I assume it has something to do with the fact that help
sometimes launches a pager (i.e. less
), but I haven't really looked into it yet.
Furthermore:
[GCC 6.2.0 20160914] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> id(string.letters)
140641450093232
>>> help(string)
>>> id(string.letters)
140641450093232
@dschep that's not so surprising, the new string.letters
just happens to get the same ID, same as this question. If you assign the original string.letters
to a variable the updated string.letters
will have a different ID.
Same on Ubuntu 16.10, CPython 2.7
but not CPython 3.5