22

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?

mikemaccana
  • 110,530
  • 99
  • 389
  • 494

1 Answers1

29

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.

PaulMcG
  • 62,419
  • 16
  • 94
  • 130
  • 1
    Interesting. I'm aware of the replacement of string functions with string methods, but pylint marks any importing of 'string' as a error itself. A bug in pylint perhaps? – mikemaccana May 20 '13 at 15:03
  • Does it flag importing of specific names, like `from string import ascii_lowercase` also? – PaulMcG May 20 '13 at 16:25
  • Yes. pylint still return `Uses of a deprecated module 'string'` with `from string import ascii_lowercase`. – mikemaccana May 20 '13 at 16:42
  • 1
    That is a bug in pylint then. – PaulMcG May 20 '13 at 16:46
  • 3
    A little research shows you're right: http://www.logilab.org/ticket/2481 . If you add this link to your answer I'll mark it as correct. – mikemaccana May 20 '13 at 16:59
  • 1
    I didn't come back for 10 years, but I see you did add a link to your answer so I have now marked it as correct. – mikemaccana Jun 15 '23 at 12:42