Content of the file I want to read(d0.txt)
我正在学习python,我的作业如下所示。我不知道我在哪里犯了错误,它表明“类型'对象'NoneType'没有len()”。任何人都可以帮我解释为什么它会显示此错误消息?
import sys
import os.path
# Add your function definitions here
def getData():
fLocation="C://TEMP//"
print("Assumed file location is at: ", fLocation)
fName = input("\nPlease enter a file name with its extension (ex. XXX.txt): ")
fin = open(fLocation + fName, 'r')
aStr = fin.read()
aList = aStr.split()
aLen=len(aList)
def main():
integersInAstr = getData()
if (len(integersInAstr) == 0):
print('*' * 30 + "\nReceived an empty string and no number to process, so the",
"program terminates.\n")
sys.exit()
else:
print('*' * 30 + "\nReceived data items:\n" + integersInAstr)
BTW这是我执行程序时得到的:
假设文件位置位于:/ Users / Ivan / Desktop /
Please enter a file name with its extension (ex. XXX.txt): d0.txt
Traceback (most recent call last):
File "/Users/Ivan/Desktop/search.py", line 89, in
main( )
File "/Users/Ivan/Desktop/search.py", line 42, in main
if (len(integersInAstr) == 0):
TypeError: object of type 'NoneType' has no len()