24 Aug 2004 TazForEver   » (Journeyer)

python debugging : repr vs. str

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.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!