Python问题——AttributeError: 'NoneType' object has no attribute 'append'


python提示AttributeError: 'NoneType' object has no attribute 'append'

 

 

Python问题——AttributeError: 'NoneType' object has no attribute 'append'

f=open("data.csv")
for line in f:
line = line.strip("\n")
ls = line.split(",")
lt=[]
for word in ls:
word=word.strip()
lt=lt.append(word)

print(",".join(lt))
f.close()


把lt= lt.append(word)改为lt.append(word)后问题解决。

原因:append会修改a本身,并且返回None。不能把返回值再赋值给a。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM