What is the equivalence in Python 3 of letters in Python 2?

Question:

In Python 2 you get

>>> from string import *
>>> letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

But in Python 3, you get

>>> from string import *
>>> letters
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'letters' is not defined

It’s not defined, whereas digits and whitespace are.

What is the equivalence of letters from the string module in Python 3?

Answers:

Try using: string.ascii_letters instead of just letters, here.

More information here: http://docs.python.org/release/3.1.3/library/string.html#string-constants


Update:

As @wim noted in the previously posted comment, this suggestion to use string.ascii_letters in Python 3 is not equivalent to the letters in Python 2. Like wim noted, string.ascii_letters is not locale-dependent while letters is locale-dependent.

I hope this suggestion can still be helpful, though, but wanted to include the feedback from @wim and the docs.

Answered By: summea
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.