简体   繁体   中英

'list' object has no attribute 'split'

I've got this code to retrieve the name of an investment fund starting from the input ISIN code:

isin = raw_input("isin of the fund? ")  
name = c.execute("select name from funds where isin like ?", ('%'+isin+'%',))  
s = c.fetchall()

Now I need to process the name splitting it and removing certain words:

stop_words=['Cap','Ptf', '(EUR)', 'EUR', 'USD', '(D)', 'A', 'B', 'C', 'D', 'I', 'E' ]

final_list=[]
for i in s[0].split():
    if i not in stop_words:
        final_list.append(i)

print(" ".join(final_list))

and what I got as error is:

AttributeError: 'list' object has no attribute 'split'

I'm a newbie and understand the problem, I just don't understand how to convert my list in a string to split it. Thank you for your help.

Edit: grammar

The result of cursor.fetchall() is a list of lists , so you'd need to index into it twice, eg:

rows = c.fetchall()
if rows:
    name = rows[0][0]
    ...

However, since ISIN codes are supposed to be unique, you could probably use cursor.fetchone() to fetch just a single row and also get rid of LIKE :

c.execute("select name from funds where isin = ?", (isin,))
row = c.fetchone()
if row:
    name = row[0]
    ...

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