我想遍历结果集,清理每个项目,然后追加到列表中。我在这里有问题:
当尝试追加列表时,出现错误,即'AttributeError:'NoneType'对象没有属性'append'。我试图克服if pass,但是我没有工作。有任何想法吗?
以下是输入内容:
I_Details =
['27Dec2017']
['04Jan2018']
['22,000,000USD(fiat)']
['20,000,000USD']
['China,Japan,UnitedStates']
['ZIL']
['Utility-token']
['No']
[ETH,,]
[40%-MiningRewards,,30%-Company,Team,Agencies,,30%-Early&CommunityContributors]
[(ZIL)]
[ETH,,,'return11.89x']
这是我的尝试:
Campaign_info_1 = list()
for Detail in I_Details:
Campaign_info = Detail.contents
Campaign_info = str(Campaign_info)
if Campaign_info==None or Campaign_info=="":
pass
Campaign_info_1 = Campaign_info_1.append(Campaign_info)
print(Campaign_info)
答案 0 :(得分:0)
Campaign_info_1 = Campaign_info_1.append(Campaign_info)
必须更改为Campaign_info_1.append(Campaign_info)
。 Append会使列表发生变化,无需重新分配并导致错误。
Campaign_info_1 = list()
for Detail in I_Details:
Campaign_info = Detail.contents
Campaign_info = str(Campaign_info)
if Campaign_info==None or Campaign_info=="":
pass
Campaign_info_1.append(Campaign_info)
print(Campaign_info)