Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylint says 'string' module is deprecated. What's the new way to get range of lowercase characters?

Tags:

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?

like image 338
mikemaccana Avatar asked May 20 '13 14:05

mikemaccana


People also ask

What is the string module in Python?

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.

Do I need to import string in Python?

It's a built-in module and we have to import it before using any of its constants and classes.

What is a string class in Python?

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.

What are the characters in Python?

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.


1 Answers

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.

like image 98
PaulMcG Avatar answered Nov 09 '22 22:11

PaulMcG