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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top