【发布时间】:2016-01-08 09:55:48
【问题描述】:
我正在尝试将多个变量保存到一个文件中。例如,在商店中保存商品,因此我尝试将商品价格、名称和代码保存到一个文件中,并将多个商品保存到同一个文件中
def enter_item_info():
count = 0
count1 = 0
print("how many items are you entering?")
amount = int(input("Items = "))
data = [[0,1,2]] * amount
file = (open('fruit.txt','wb'))
while count < amount:
data[0 + count1][0] = input("Code")
data[0 + count1][1] = input("NAme")
data[0 + count1][2] = input("Price")
count1 = count1 + 1
count = count + 1
print("")
pickle.dump(data , file)
file.close()
amount = str(amount)
file1 = (open('amount.txt','wb'))
pickle.dump(amount , file1)
file1.close()
【问题讨论】:
-
你尝试了什么,遇到了什么问题?
-
您的代码没有正确缩进 - 请确保所有缩进都是应有的,因为这在 Python 中相当重要。
标签: python file pickle writing