-1
我有数据的文件:文件,列表,新行和附加()?
ABC acd IGK EFG
GHQ ghq acb efg
IJK ijk gtt ttg
我要分拆旗下的线条和每行采取一些数据和它们连接成一个列表。像这样:
a = ['acd', 'ghq', 'ijk']
到目前为止我做了以下。
li = []
with open('file.txt') as fl:
for f in fl:
f = f.split()
li = li.append(f[2])
但我收到以下错误:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
AttributeError: 'NoneType' object has no attribute 'append'
是否有人可以帮我完成的代码?
你甚至[谷歌的错误消息](https://www.google.co.in/search?q=AttributeError%3A+%27NoneType%27+object+has+no+attribute+%27append%27)? –
像'list's和'dict'这样的可变对象就地变化的方法,比如'list.append()'和'dict.clear()',不会返回被更改的对象。他们有效地返回'None'。 – martineau