I was just pylinting some code and noticed a colleague had imported the old Python 'string' module, not to use any functions from it but simply to have access to the constant 'string.lowercase'.
I removed the deprecated import and substituted 'abcdef...' for string.lowercase, but I was wondering: is there a better way I should be doing this?
The string module contains a number of functions to process standard Python strings, as shown in Example 1-51. In Python 1.5. 2 and earlier, the string module uses functions from the strop implementation module where possible.
It's a built-in module and we have to import it before using any of its constants and classes.
Python has a built-in string class named "str" with many handy features (there is an older module named "string" which you should not use). String literals can be enclosed by either double or single quotes, although single quotes are more commonly used.
Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.
string
itself is not deprecated, just those methods like string.join
that are better accessed through a string object. You can still import string
, and get string.ascii_lowercase
for what you want.
pylint's reporting this as an error is a known bug - see http://www.logilab.org/ticket/2481.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With