how to remove u from sqlite3 cursor.fetchall() in python

后端 未结 4 1109
情歌与酒
情歌与酒 2021-02-13 04:19
import sqlite3
class class1:
def __init__(self):
    self.print1()
def print1(self):
    con = sqlite3.connect(\'mydb.sqlite\')
    cur = con.cursor()
    cur.execute(\"         


        
4条回答
  •  [愿得一人]
    2021-02-13 05:02

    The u prefix indicates that the string is an Unicode string. If you're sure that the string is a basic ASCII string, you can transform the unicode string into a non-unicode one with a simple str().

    Example :

    unicode_foo = u"foo"
    print unicode_foo
    >>> u"foo"
    
    print str(unicode_foo)
    >>> "foo"
    

    In your case, with a list of tuples, you'll have to do such with a python list comprehension :

    ar = [[str(item) for item in results] for results in cur.fetchall()]
    

    Where results is the list of tuples returned by fetchall, and item are the members of the tuples.

提交回复
热议问题