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?
You’ve assigned a string (instance of
str) to a variable namedstring. 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 namestringstopped referring to thestringmodule and started referring to astrinstance.