失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > AttributeError: 'function' object has no attribute 'Document'报错解决

AttributeError: 'function' object has no attribute 'Document'报错解决

时间:2021-03-14 23:05:18

相关推荐

AttributeError: 'function' object has no attribute 'Document'报错解决

原因是函数名称和系统中的某个名称相同的,替换另外的名字就行了

报错代码:

#读取docx中的文本代码示例import docxdef docx():file=docx.Document(filename)raw_words = '' #保存所有的单词#输出每一段的内容for para in file.paragraphs:raw_words += para.text #把每段的单词添加到字符串里面raw_words = raw_words.lower()#print(raw_words)words = re.findall('[a-z]+',raw_words) #得到所有的英文单词,排除了汉语单词,各种符号return words

修改后的代码

#读取docx中的文本代码示例import docxdef docx_file():file=docx.Document(filename)raw_words = '' #保存所有的单词#输出每一段的内容for para in file.paragraphs:raw_words += para.text #把每段的单词添加到字符串里面raw_words = raw_words.lower()#print(raw_words)words = re.findall('[a-z]+',raw_words) #得到所有的英文单词,排除了汉语单词,各种符号return words

替换文件名就可以了,def docx_file():

如果觉得《AttributeError: 'function' object has no attribute 'Document'报错解决》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。