1
我一直在研究一个小的联系人导入器,现在我试图实现一个块,它根据要导入的联系人数自动选择输出文件格式。从字典python中的列表中选择值
然而,每次都导致错误:
KeyError: 'q'
我想不出我的生活为什么发生这种情况,我很想提供任何帮助。
我对可扩展性的想法是,字典personDict
的格式是personDict = {nameid:[name,email]}
,但没有任何效果。
任何帮助是好的帮助,
感谢
def autoFormat():
while True:
name = input("Enter the person's name \n")
if name == "q":
break
email = input("Enter the person's email \n")
personDict[name] = [name, email]
if len(personDict) <= 10:
keyValue = personDict[name]
for keyValue in personDict:
for key, value in personDict.iteritems():
combined = "BEGIN:VCARD\nVERSION:4.0\n" + "FN:" + name + "\n" + "EMAIL:" + email + "\n" + "END:VCARD"
fileName = name + ".vcl"
people = open(fileName, 'a')
people.write(combined)
people.close()
print("Created file for " + name)
autoFormat()