python - python打印项目列表
问题描述
所以我对python很陌生,我有一个问题,我真的无法理解。我不断收到来自 firebase 上传器脚本的错误。它只适用于 1 个项目,但是从我的 json 文件中我需要它来获取多个字段,并且每次我尝试添加另一个字段以供它读取时,它都会给我一个错误
“AttributeError:'dict' object”没有属性“item”。
因此,下面是更改后停止工作的代码部分。
def main():
pool = Pool(processes=100)
data= []
try:
data = getData(JSON_FILE)
except:
print("please format the json file properly. Parsing error")
print(len(data))
index = 0
for item in data:
print(str(index)+' items out of '+str(len(data))+' is done.')
if item.item['email_client', 'persoana_contact'] != '' :
postClientData(items)
index+=1
pool.close()
这一点效果很好:
for item in data:
print(str(index)+' items out of '+str(len(data))+' is done.')
if item['persoana_contact'] != '' :
postClientData(item)
那么我做错了什么,我怎样才能让脚本从我的 json 文件中获取超过 1 个项目并按应有的方式创建客户端实体?
解决方案
你的问题出在item.item['email_client', 'persoana_contact'] != ''
for item in data:
...
# wrong
# if item.item['email_client', 'persoana_contact'] != '' :
..
# maybe you need something like this ?
if item['email_client'] != '' or item['persoana_contact'] != '':
...