Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of a deprecated module 'string'

Tags:

python

string

I just ran pylint on my code and it shows up this message:

Uses of a deprecated module 'string'

I am using the module string for join / split mainly.

>>> names = ['Pulp', 'Fiction']
>>> import string
>>> fullname = string.join(names)
>>> print fullname
Pulp Fiction

Above is an example. In my code I have to make use of split and join a lot and for that I was using the string module.

Has this been deprecated? If yes, what is the way to handle split/ join in Python 2.6? I have tried searching but I could not find myself being clear so I asked here.

like image 811
user225312 Avatar asked Jul 03 '10 08:07

user225312


2 Answers

Equivalent to your code would be:

' '.join(names)

string is not deprecated, deprecated are certain functions that were duplicates of str methods. For split you could also use:

>>> 'Pulp Fiction'.split()
['Pulp', 'Fiction']

In docs there is a full list of deprecated functions with suggested replacements.

like image 71
SilentGhost Avatar answered Nov 02 '22 12:11

SilentGhost


not all functions from "strings" are deprecated. if you want to use a function from strings which is not deprecated, then remove a string from deprecated-modules configuration in pylint config.

[IMPORTS]
deprecated-modules=string
like image 27
RomanI Avatar answered Nov 02 '22 14:11

RomanI