>>> import csv
>>> with open('tmp.csv', 'wb') as stream:
... csv.writer(stream).writerow(['choice'])
...
>>> lst = []
>>> with open('tmp.csv', 'rb') as stream:
... for row in csv.reader(stream):
... lst.append(row)
...
>>> from PyQt4.QtCore import QString
>>> s = QString(u'choice')
>>> lst.index(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: PyQt4.QtCore.QString(u'choice') is not in list
>>> lst
[['choice']]
>>> lst[0].index(s)
0
这与编码无关。在
发生错误的原因很简单,因为从csv文件读取的列表中没有字符串:
csv读取器为文件中的每一行返回字符串列表。在
相关问题 更多 >
编程相关推荐