import time
from random import randint
import pickle
MaTC = 1
MaTC = pickle.dump(MaTC, open("MaTCFile.txt", "wb"))
AnTC = 2
AnTC = pickle.dump(AnTC, open("AnTCFile.txt", "wb"))
AuTC = 3
AuTC = pickle.dump(AuTC, open("AuTCFile.txt", "wb"))
AlTC = 3
AlTC = pickle.dump(AlTC, open("AlTCFile.txt", "wb"))
JaTC = 3
JaTC = pickle.dump(JaTC, open("JaTCFile.txt", "wb"))
print("Hello Jacob")
time.sleep(1)
print("Choose an option!")
print("(1) Selecting Cleaners")
print("(2) Edit Cleaning Information")
print("(3) Reserved")
MenuChoice = input(": ")
if MenuChoice == "1":
print("Selecting Cleaner Function")
elif MenuChoice == "2":
print("(1) Check cleaning info")
print("(2) Enter New Cleaning info")
InfoSelect = input(": ")
if InfoSelect == "2":
Mare = { "Mares Times Cleaned": MaTC}
Andre = { "Andres Times Cleaned": AnTC}
Al = { "Als Times Cleaned": AlTC}
Austin = { "Austins Times Cleaned": AuTC}
Jacob = { "Jacobs Times Cleaned": JaTC}
pickle.dump( Mare, open ("MaresFile.txt", "wb"))
pickle.dump( Jacob, open ("JacobsFile.txt", "wb"))
pickle.dump( Andre, open ("AndresFile.txt", "wb"))
pickle.dump( Austin,open ("AustinsFile.txt", "wb"))
pickle.dump( Al, open ("AlsFile.txt", "wb"))
print(Mare)
print(Austin)
print(Jacob)
print(Andre)
print(Al)
好的,基本上我要实现的是在第一次运行程序时,将MaTC,AnTC,AuTC,AlTC,和JaTC变量预设为1,2,3,3和3。但是当我想加2表示MaTC使其为3时,当我再次启动程序时,我希望它在启动时等于3。我几天前刚开始使用python,我很想得到反馈!你知道吗
使用异常处理文件不存在的情况(即程序的第一次运行)
我也倾向于使用dict将所有变量存储在一个文件中:
因为这将使程序更易于管理。你知道吗
这是你程序的重构版本。它使用
pickle
模块并演示pickletools
、zlib
和其他一些模块的用法。希望这些代码能帮助您进一步编写程序。你将来可能想研究的一个课题是数据库。你知道吗相关问题 更多 >
编程相关推荐