这里我在ipython上运行了两行代码,这些代码是我之前读过的以制表符分隔的值并且已经按行分割的大文本文件:
In [30]: data = [(int(e[0]),e[1],e[2],int(e[3])) for e in d.split('\t') for d in dat]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/max/verk/data/build/x86_64/bin/ipython in <module>()
----> 1 data = [(int(e[0]),e[1],e[2],int(e[3])) for e in d.split('\t') for d in dat]
ValueError: invalid literal for int() with base 10: 'T'
In [31]: data = [(int(e[0]),e[1],e[2],int(e[3])) for e in (d.split('\t') for d in dat)]
In [32]: len(data)
Out[32]: 173503
In [33]:
......那么这里发生了什么?为什么第30行的代码不起作用,为什么当解决方案似乎与列表理解相关时,错误看起来像将字符串转换为int一样?