AttributeError: 'module' object has no attribute 'lowercase'
2020 addendum: Note string.lowercase
was for Python 2 only.
In Python 3, use string.ascii_lowercase
instead of string.lowercase
Python 3.6.8 [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin>>> import string>>> string.lowercaseTraceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: module 'string' has no attribute 'lowercase'>>> string.ascii_lowercase'abcdefghijklmnopqrstuvwxyz'
After some discussion in the comments, it turned out (as it usually does when builtin modules suddenly seem to give AttributeErrors
) that the problem was that another module named string
was shadowing the builtin one.
One way to check this is to look at the __file__
attribute of the module, or just look at the repr
itself:
>>> print string<module 'string' from '/usr/lib/python2.7/string.pyc'>
if the from
doesn't point to the right place, you've got the wrong module being read.
Solution: delete/rename the offending string.py
/string.pyc
files.