2012-11-22 123 views
1

我遇到了python變量作用域的問題。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" 

這版畫「無法到達頭」,當我假設數量不應爲零。爲什麼它沒有看到弧度?謝謝

+4

你確定你沒有在被排除的代碼的其他地方修改'arcount'嗎?請張貼代碼 – inspectorG4dget

+2

您正在修改'arcount',直接或通過修改'header'。 – LSerni

回答

1

因爲Python是強類型的,並且u'0''0'都不等於0