6

I ran into a strange issue today. I was using the Python standard library's string module's letters variable and noticed that the result in bpython was not the same as the result in vanilla python.

I'm using Python 2.7.3 and bpython 0.10.1 and virtualenv 1.8.4. Here is what I'm seeing.

$ bpython
>>> import string
>>> string.letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'


$ python
>>> import string
>>> string.letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

I'm not sure that it matters but I'm running this on xubuntu 12.10.

Can someone please explain what is going on here?

Adam
  • 15,537
  • 2
  • 42
  • 63
Matthew J Morrison
  • 4,343
  • 3
  • 28
  • 45
  • my guess is they are just different implementations where one said `string.letters = string.ascii_upper + string.ascii_lower` and the other did `string.letters = string.ascii_lower + string.ascii_upper`, I dont think it will have any effect on any of your programs (unless you are trying to do `string.letters[:26]` or something) – Joran Beasley Apr 24 '13 at 15:48
  • That's odd: using `string.letters` I get the same results as you, but using `string.ascii_letters` I get `'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'` in both python and bpython. – dusan Apr 24 '13 at 17:16

1 Answers1

4

From the docs, string.letters is defined as

The concatenation of the strings lowercase and uppercase described below. The specific value is locale-dependent, and will be updated when locale.setlocale() is called.

So it could be that your locale is different.

Thanakron Tandavas
  • 5,615
  • 5
  • 28
  • 41
Dmitry Shevchenko
  • 31,814
  • 10
  • 56
  • 62
  • 4
    I guess that could be right: `bpython` shows a `locale` of `('en_US', 'UTF-8')` and `python` shows a `locale` of `(None, None)` – Matthew J Morrison Apr 24 '13 at 14:58
  • It turns out that the locale does not seem to affect it. I changed the locale in the `python` repl to `('en_US', 'UTF-8')` and `string.letters` was the same. – Matthew J Morrison Apr 24 '13 at 15:04