Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'str' object has no attribute 'punctuation' [closed]

Tags:

python

string

I'm probably being really dumb here, but I can't figure out this error:

'str' object has no attribute 'punctuation'

This occurs on the line:

docLines[counter][counter2] = [(docLines[counter][counter2]).translate(None, string.punctuation)]

Where docLines[counter][counter2] is just a single word.

Any ideas where I'm going wrong with is line of code?

like image 303
djcmm476 Avatar asked Dec 07 '22 11:12

djcmm476


1 Answers

You've assigned a string (instance of str) to a variable named string. Rename the variable and the problem will go away.

To debug this, add print repr(string) before the offending line and it will print a string instance. A number of such prints in various places in your module will help you discover where the name string stopped referring to the string module and started referring to a str instance.

like image 52
user4815162342 Avatar answered Feb 19 '23 17:02

user4815162342