我是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('!')
Run Code Online (Sandbox Code Playgroud)
由于下面的错误,我无法通过计数功能.我做了一些研究并尝试导入一些库,但这没有用.有人能引导我朝正确的方向发展吗?我感觉很失落.
text.count(':') + text.count(';') + \
AttributeError: 'bool' object has no attribute 'count'
Run Code Online (Sandbox Code Playgroud)
您的代码中有一条错误的行:
text = InputFile.readable()
Run Code Online (Sandbox Code Playgroud)
返回boolean没有属性的count
本来应该:
text = InputFile.read()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
830 次 |
| 最近记录: |