Nazerke
Nazerke

Reputation: 2098

python scope issue

I'm having problems with python variable scopes.

def getIP(data,address):
    header = Header.fromData(data,0);
    arcount = header._arcount   //at this point arcount is some non-zero number

later in the code (still inside the method getIP) I want to see if arcount is zero or not:

...
    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"

And this prints "can't reach header", when I was assuming arcount shouldn't be zero. Why it doesn't see arcount? Thanks

Upvotes: 1

Views: 95

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798556

Because Python is strongly typed, and neither u'0' nor '0' are equal to 0.

Upvotes: 1

Related Questions