1

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

asked Nov 22, 2012 at 23:19
2
  • 4
    Are you sure you're not modifying arcount anywhere else in the excluded code? Please post that code Commented Nov 22, 2012 at 23:22
  • 2
    You're modifying arcount, either directly or through a modification of header. Commented Nov 22, 2012 at 23:24

1 Answer 1

1

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

answered Nov 22, 2012 at 23:30
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.