Today, i've wasted one hour debugging a network app : receive an UDP packet, unpack it and insert data into a PostgreSQL database. Quite simple. The program sending data is written in C.
I was getting a pg error about bad queries. So i added a try...except and a print statement on exception. Everything looked OK, i didn't understand what was wrong. So i opened a psql shell and a python shell, dumped there my query. Ran fine. I was crazy. I spent 15 minutes sending packet and watching my error log ...
Then repr came !(Python lib)
so i replace my print 'Query was %s' % (my_query,) by print 'Query was %s' % (repr(my_query),) ... there were some non-printable chars in my data (C '\0' grrrr /me stupid). repr displays them, str doesn't.
Next time, i'll be more carefull with string and i'll use repr each time i'll need to print data in an error messages.