简体   繁体   中英

Python3: SQlite3 list format

when i fetch data from a table in SQlite3 it formats each value ('value',) the data in the column: Regi Bob Jeff

how to i remove/ stop the extra round brackets and comma?

c.execute('SELECT Name from information')
data = c.fetchall()
valNameNS = data
valName = str(data)
valNameL = list(valNameNS)
print(valNameL)
[('Regi',), ('Bob',), ('Jeff',)]

Thanks

The items in parenthesis with commas are length-one tuples. Use a list comprehension to extract them.

new_list = [x[0] for x in valNameL]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM