def get_all_cust_info():
"""function displays data as a list of dict of base data"""
reader = csv.DictReader(open("base data.csv", "rb"))
all_rows = list()
for row in reader:
all_rows.append(row)
return all_rows
get_all_cust_info() 的第一行输出。
[{'totcust': '2', 'delfee': '1308', 'bskt_bnd': '0', 'distribution ': '>1', 'totords': '199', 'netsales': '1851'}, .......]
我想创建一个删除键('delfee'和'netsales')并添加新键'order value'的新函数。这就是我所做的
def cust_state():
s = get_all_cust_info()
for d in s:
if d.has_key('delfee'):
del d['delfee']
print s
但我收到了这个错误。
AttributeError: 'list' object has no attribute 'has_key'
非常感谢您对此的帮助。