Monday, November 23, 2009

IDLE & Python 2.6 escaping mishap

Here's an odd one that can catch out a newbie (well, me, at least):

x = '\x0'


Do that in the interpreter and it'll tell you "ValueError: invalid \x escape"... put it in a source file and execute it with F5 and nothing will happen, other than focus switching to the interpreter window. No message, no nothing. Had to do a binary(ish) search, commenting out the whole program minus one print statement and checking that it runs, then commenting out about half the file and homing in on the buggy line that way - I was writing a unit test which checked that the output of a particular function was a zero byte (the most trivial case of about 12 tests).

When you do it in the IDLE/Python 3.1 bundle, you get a notification as expected, but not in the 2.6 version for the Mac. Pity pygame doesn't work in Python 3 yet.

No comments:

Post a Comment