我连接到一个sqlite数据库,并希望在所选内容上执行代码的和平。在
import langid
...#connecter etc. to database
languagedata = []
connector = sqlite3.connect("GERMANY.db")
selecter = connector.cursor()
selecter.execute(''' SELECT title FROM DATAGERMANY''') #select only the title
for row in selecter: #iterate through all the rows in db
languagedata.append(row) #append to list
if languagedata is not None: #check weather datatype is None or not
print (langid.classify("{}")).format(languagedata[-1]) #-1 for always take the last appended attribute of the list
else:
continue #if datatype is none, continue with next one
我开始的时候没有if语句。这给了我以下错误信息:
AttributeError: 'NoneType' object has no attribute 'format'
。在
所以我添加了if语句来检查数据是否属于None
类型。
它现在适用于第一轮迭代。它接受列表的第一个属性并将其传递给langid
。但后来我得到了和上面一样的错误信息。在
我做错什么了?在
请注意,并不是所有的rows
都会返回数据。他们中的一些人没有数据。在
看起来像代码中的语句:
print (langid.classify("{}")).format(languagedata[-1])
一定是
print (langid.classify("{}.format(languagedata[-1]")))
有关字符串格式的详细信息here
相关问题 更多 >
编程相关推荐