我在使用 python 变量范围时遇到问题。
def getIP(data,address):
header = Header.fromData(data,0);
arcount = header._arcount //at this point arcount is some non-zero number
稍后在代码中(仍在方法getIP中)我想看看arcount是否为零:
...
elif firstRR._type==RR.TYPE_NS:
while(nscount!=0):
print "arcount: ",arcount //here it gives 0. why?
if(arcount!=0):
print "arcount isn't 0"
else:
print "can't reach header"
当我假设arcount不应该为零时,这会打印“无法到达标题”。为什么它没有看到arcount?谢谢