简体   繁体   English

“列表”对象没有属性“分割”

[英]'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代码开始检索投资基金的名称:

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: cursor.fetchall()的结果是一个list列表 ,因此您需要对其进行两次索引,例如:

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 : 但是,由于ISIN代码应该是唯一的,因此您可以使用cursor.fetchone()来仅获取一行,并摆脱LIKE

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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