'str'对象没有属性'标点符号'

djc*_*476 3 python string

我可能在这里真的很蠢,但我无法弄清楚这个错误:

'str' object has no attribute 'punctuation'
Run Code Online (Sandbox Code Playgroud)

这发生在这一行:

docLines[counter][counter2] = [(docLines[counter][counter2]).translate(None, string.punctuation)]
Run Code Online (Sandbox Code Playgroud)

哪里__CODE__只是一个单词.

我出错的任何想法?

use*_*342 12

您已str为名为的变量分配了一个字符串(实例)string.重命名变量,问题就会消失.

要调试它,print repr(string)在违规行之前添加,它将打印一个字符串实例.模块中不同位置的许多此类打印将帮助您发现名称string停止引用string模块的位置并开始引用str实例.