import sqlite3
class class1:
def __init__(self):
self.print1()
def print1(self):
con = sqlite3.connect('mydb.sqlite')
cur = con.cursor()
cur.execute("select fname from tblsample1 order by fname")
ar=cur.fetchall()
print(ar)
class1()
gives an output as shown below
[(u'arun',), (u'kiran',), (u'kulku',), (u'sugu',)]
i need to remove u from the array and i need output as shown below
['arun', 'kiran', 'kulku', 'sugu']
the u tells you that these are unicode strings. to print the list of tuples in the format you specified you could use:
edit:// Example for KIRAN with u and , in the result set:
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 simplestr()
.Example :
In your case, with a list of tuples, you'll have to do such with a python list comprehension :
Where
results
is the list of tuples returned byfetchall
, anditem
are the members of the tuples.If you need that strings retrieved from your sqlite database be returned as UTF-8 instead of Unicode, set-up your connection accordingly using the text_factory propery:
See this for the details: http://docs.python.org/library/sqlite3.html#sqlite3.Connection.text_factory
That takes care of the "u" in front of your strings. You'll then have to convert your list of tuples to a list: