sqlite3 decode error

David Pratt fairwinds at eastlink.ca
Tue Nov 8 15:27:25 EST 2005


Recently I have run into an issue with sqlite where I encode strings 
going into sqlite3 as utf-8.  I guess by default sqlite3 is converting 
this to unicode since when I try to decode I get an attribute error 
like this:

AttributeError: 'unicode' object has no attribute 'decode'

The code and data I am preparing is to work on postgres as well a 
sqlite so there are a couple of things I could do.  I could always 
store any data as unicode to any db, or test the data to determine 
whether it is a string or unicode type when it comes out of the 
database so I can deal with this possibility without errors. I will 
likely take the first option but I looking for a simple test to 
determine my object type.

if I do:

 >>>type('maybe string or maybe unicode')

I get this:

 >>><type 'unicode'>

I am looking for something that I can use in a comparison.

How do I get the type as a string for comparison so I can do something 
like

if type(some_data) == 'unicode':
	do some stuff
else:
	do something else

Regards,
David









More information about the Python-list mailing list