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