简体   繁体   中英

Converting tuple into list does not work

I query my SQlite Database with a loop to retrieve data from it.

connector = sqlite3.connect("somedb.db")
selecter = connector.cursor()
selecter.execute(''' SELECT somedata FROM somedb''')
for row in selecter:
    l = list(row)
    print (l)
    print (type(l))

Then I try do use formatting to append the retrieved data to something else

this = detect.that( "{}", pick, summary).format(l)

But it comes back with this:

AttributeError: 'tuple' object has no attribute 'format'

I also tried this

s = " ".join(str(row) for row in selecter)

for the l = list(row) statement but it comes back with the same errormessage and it seems that it converts all my 50 separate selections into one string what I dont want.

However, when I run this

print (type(l))

or

print (type(s))

it returns me list or string as a type. So the converting worked, but the .format does not take it because it thinks it is a tuple.

How comes?

将您的detect.that行更改为:

this = str(detect.that("{}", pick, summary)).format(1)

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