D
David R. Stockwell (wg-xiao)
Hi,
I spent a couple hours today trying to track down this bug
It went something like this
def fcn(day):
print "day is ", day
if (day < 10):
print "day is less than 10"
else:
if day < 20 :
print "day is less than 20 but greater than 10"
fcn(14)
It never fell into the < 20 but > 10 loop in my 'code from my file'
but if i ran interactively it always did.
And thats what drove me crazy until I came up with this check
as a replacement:
instead of if day < 10:
i tried
if (10 - day) > 0:
blah......
And when I did that I got an exception immediately saying I couldn't
compare a string to an int.
And that was when I remembered, in my code (file version) there was a point
where under certain circumstances I was setting day to "N/A" and indeed it
was really a string.
In the file version this was just one function of a 600 line file. So its
almost like I could have saved myself the trouble by either using some sort
of hungarian notation or perhaps make some rules, or just always do checks
like that to catch little sneaky errors.....
David
I spent a couple hours today trying to track down this bug
It went something like this
def fcn(day):
print "day is ", day
if (day < 10):
print "day is less than 10"
else:
if day < 20 :
print "day is less than 20 but greater than 10"
fcn(14)
It never fell into the < 20 but > 10 loop in my 'code from my file'
but if i ran interactively it always did.
And thats what drove me crazy until I came up with this check
as a replacement:
instead of if day < 10:
i tried
if (10 - day) > 0:
blah......
And when I did that I got an exception immediately saying I couldn't
compare a string to an int.
And that was when I remembered, in my code (file version) there was a point
where under certain circumstances I was setting day to "N/A" and indeed it
was really a string.
In the file version this was just one function of a 600 line file. So its
almost like I could have saved myself the trouble by either using some sort
of hungarian notation or perhaps make some rules, or just always do checks
like that to catch little sneaky errors.....
David