我无法弄清楚如何修复我一直收到的错误,我将它们放在下面代码的底部。
import random
def random_number_file_create(min, max, filenames, entries):
random_number_file = open(FILENAME, "w")
for i in range (entries):
number = str(random.randint(min, max))
random_number_file.write(number + "\n")
random_number_file.close()
def lines_print(filename):
random_number_file = open(FILENAME, "r")
line = random_number_file.readline()
while line != "":
print(line, end="")
line = random_number_file()
random_number_file.close()
def lines_count(filename):
random_number_file = open (FILENAME, "r")
line = random_number_file.readline()
count = 0
for number in random_number_file:
count += 1
return count
random_number_file.close()
def total_numbers_in_file(filename):
random_number_file = open (FILENAME, "r")
line = random_number_file.readline()
total=0
for number in random_number_file:
total = int(number)
return total
random_number_file.close()
FILENAME= "numbers.txt"
random.seed(83)
random_number_file_create(50,100,FILENAME,20)
lines_print(FILENAME)
print()
entries = lines_count(FILENAME)
total = total_numbers_in_file(FILENAME)
average = round(total/entries)
print("Entries:", entries)
print("Total:", total)
print("Average:", average)
#错误# Traceback(最近一次调用最后一次): 文件" hw8.py",第41行,in lines_print(文件名) 文件" hw8.py",第18行,在lines_print中 line = random_number_file() TypeError:' _io.TextIOWrapper'对象不可调用
答案 0 :(得分:-1)
提供参考案例:
另一个类似的案例,错误提示是:
Traceback(most recent call last):
File "ex17.py", line 18, in <module>
input<'?'>
TypeError: 'file' object is not callable.
当我运行我的模块时,系统会向您显示与您相同的错误,但我的错误与明显的提问者相同。因此,通过更改输入&#39;变量作为不同的变量&#39; input_1&#39;,我解决了错误。
我希望我的回答可以帮助你,实际上我是python的新手,我可以阅读你的代码并理解,但我无法找到真相。