繁体   English   中英

AttributeError:'bool'对象没有属性'count'

[英]AttributeError: 'bool' object has no attribute 'count'

我是Python的新手,我在下面编写此代码。

fileName = input("Enter the file name: ")
InputFile = open(fileName, 'r')
text=InputFile.readable()

sentences = text.count('.') + text.count('?') + \
            text.count(':') + text.count(';') + \
            text.count('!')

由于以下错误,我无法通过计数功能。 我进行了一些研究,并尝试导入一些库,但这没有用。 有人可以指引我正确的方向吗? 我感到很失落。

 text.count(':') + text.count(';') + \
AttributeError: 'bool' object has no attribute 'count'

您的代码中有一条越野车:

text = InputFile.readable()

返回没有属性countboolean

本来应该:

text = InputFile.read()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM