Python老师帮我看看,这个怎么解决?

Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/pythonProject/first/hello world.py", line 5, in <module>
a = response.txt
AttributeError: 'Response' object has no attribute 'txt'

报错的原因是,Response类对象中没有txt这个属性(数据成员),请检查Response类的定义代码。
如果你要读取文件的话,代码如下:

content = ""
with open("response.txt") as fp:
content = fp.read()() // 前面有4个空格
print(content)
这里response.txt与当前代码文件在同一级目录下,也可以将字符串里的内容改成绝对路径
温馨提示:答案为网友推荐,仅供参考
第1个回答  2021-12-05
把第37行的numAPs这个变量的初始化值,写到第35行for循环之上,即把 numAPs=0 写到for之上,目的是初始化一下这个全局变量。
相似回答