簡體   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