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

后端 未结 4 1058
情歌与酒
情歌与酒 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 04:50

    the u tells you that these are unicode strings. to print the list of tuples in the format you specified you could use:

    >>> myformat="['%s']"%"', '".join([t[0] for t in ar])
    >>> print myformat
    ['arun', 'kiran', 'kulku', 'sugu']
    

    edit:// Example for KIRAN with u and , in the result set:

    >>> ar=[(u'u',), (u'u',), (u',,,u,,u,',)]
    >>> myformat="['%s']"%"', '".join([t[0] for t in ar])
    >>> print myformat
    ['u', 'u', ',,,u,,u,']
    

提交回复
热议问题