[英]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()
返回沒有屬性count
的boolean
本來應該:
text = InputFile.read()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.