python范围问题

标签 python scope

我在使用 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?谢谢

最佳答案

因为Python是强类型的,u'0''0'都不等于0

关于python范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13521251/

相关文章:

java - 使用CDI登录,@Produces返回缓存值

javascript - ruby 中的作用域是否像 javascript 一样被认为是功能性的,或者是 block 作用域?

python - flake8 - 忽略函数的警告

python - dataframe.plot直方图变化标签

python - 将数据帧转换为字典,忽略某些值

flutter - 变量没有被改变到 flutter 的范围之外

python - 将独立的 sklearn GaussianMixture 对数概率分数转换为总和为 1 的概率

python - 我的 scipy.sparse.linalg.eigs 发生了什么?

swift - 定义一个在 Swift 中调用自定义函数的中缀运算符

javascript - 脚本.js :10 Uncaught ReferenceError: serachFor is not defined