我遇到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?感谢
答案 0 :(得分:1)
因为Python是强类型的,u'0'
和'0'
都不等于0
。