I could be mistaken but since I backtracked to python 2.7 from 3.2 I've noticed something sqlite3 is doing that I don't like...
When I use to use my cursor.fetch method it would return (1, x, x, x) fro开发者_开发知识库m my table
but in 2.7 its returning (1, u'x' ,u'x' ,u'x')
How do I get it to stop returning that 'u' in my queries? I need to store the return values in variables and it's kind of irritating having to problem solve this.
Edit: Through a little research I've found a way...
db.text_factory = str
if there is a better way please inform me as I really don't even know what this method does, hate to be changing the wrong thing
Sigh.
(1, u'x' ,u'x' ,u'x')
is a tuple. That tuple contains four elements. One of them is an integer, the other three are unicode strings, as indicated by the u
.
If you print the entire tuple at once, it will look like the above. But that's a silly thing to do, because presumably you actually want to do something with the contents of the tuple, not the tuple itself.
If you did print result[1]
, you would see the output is just x
: the u
is not shown when you actually print it. That is the correct behaviour.
If you use the code you post, as soon as you retrieve a non-ASCII value from your datastore - someone whose name contains an accented character, for example - things will go horribly wrong.
精彩评论