简体   繁体   English

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

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

I am new to Python and I am writing this code below. 我是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('!')

I can't get past the count function because of this error below. 由于以下错误,我无法通过计数功能。 I have done some research and tried importing some libraries but that didn't work. 我进行了一些研究,并尝试导入一些库,但这没有用。 Can someone guide me in the right direction? 有人可以指引我正确的方向吗? I feel so lost. 我感到很失落。

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

There is a buggy line in your code: 您的代码中有一条越野车:

text = InputFile.readable()

Which returns a boolean that has no attribute count 返回没有属性countboolean

Should have been: 本来应该:

text = InputFile.read()

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

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