【发布时间】:2012-09-26 09:51:13
【问题描述】:
我是 Python 新手,我知道那段代码非常简单并且缺少一些语句,实际上我需要从字典中写入文件。此代码运行但仅将 dict 中的最后一项写入文件 "heba6677..." 。感谢您的帮助。
ab={'engy':'011199887765',
'wafa2':'87878857578',
'heba':'6677553636'}
for name, mobile in ab.items():
print ('Contact %s at %s' % (name, mobile))
f=open('D:\glo.txt','w')
f.write(name)
f.write(mobile)
f.close()
【问题讨论】:
标签: python python-3.x