How to store ASCII encoded python string?

micahc at gmail.com micahc at gmail.com
Mon Aug 28 15:07:02 EDT 2006


I currently have a Python program that reads in emails from a POP3
server.  As soon as the message is read in it is fed directly into a
PostgreSQL database for storage.  Later, it is broken down into it's
parts and displayed to the user.

My problem is that when I try to pass "\tsome text\xa7some more text\n"
into the database it gives me a unicode decode error.  At this point in
the program I don't know what codec it is (I won't know that until I
break apart the message later) and it may even be binary data so I just
want to store it in the database with the escape characters, not as a
decoded/encoded string.

So, how do I store "\tsome text\xa7 some more text\n" as that instead
of:
"	some text§ some more text
"

I don't have a problem escaping it so the above would look like
"\\tsome text\\xa7 some more text\\n" as long as I have a way to later
unescape it when I want to actual do something with the data.




More information about the Python-list mailing list