sqlite3 decode error

D

David Pratt

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:

I get this:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top