本文整理汇总了Python中Data.save方法的典型用法代码示例。如果您正苦于以下问题:Python Data.save方法的具体用法?Python Data.save怎么用?Python Data.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data
的用法示例。
在下文中一共展示了Data.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Data [as 别名]
# 或者: from Data import save [as 别名]
def main(self):
print
print("Romulus10's Quick Checkbook Register")
print
done = False
while not done:
print(self.account_name)
self.total = self.fin.get_total(self.transactions)
if self.total is None:
print("$0")
else:
print('$' + str(self.total))
cmd = raw_input('> ')
cmd = cmd.split(' ')
while len(cmd) < 4:
cmd.append('')
if cmd[0] == "quit":
done = True
if cmd[0] == "help":
print(self.help)
if cmd[0] == "new":
if cmd[1] != '':
self.transactions = Data.new(cmd[1])
self.account_name = cmd[1]
if cmd[0] == "load":
if cmd[1] != '':
self.transactions = Data.load(cmd[1])["transactions"]
self.categories = Data.load(cmd[1])["categories"]
self.amounts = Data.load(cmd[1])["category_amounts"]
self.account_name = cmd[1]
if cmd[0] == "save":
Data.save(self.account_name, self.transactions)
if cmd[0] == "copy":
Data.copy(cmd[1], cmd[2])
if cmd[0] == "add":
if cmd[1] != '' and cmd[2] != '' and cmd[3] != '':
self.add(cmd)
if cmd[0] == "delete":
if cmd[1] != '':
x = None
for y in self.transactions:
if y.number == int(cmd[1]):
x = y
self.transactions.remove(x)
if cmd[0] == "print":
t = PrettyTable(["Number", "Name", "Category", "Date", "Amount"])
for x in self.transactions:
t.add_row([x.number, x.name, x.category, x.date, ('$' + str(x.value))])
print(t)
if cmd[0] == "categories":
t = PrettyTable(["Name", "Current Value"])
for i in range(len(self.categories)):
t.add_row([str(self.categories[i]), ('$' + str(self.amounts[i]))])
print(t)
if cmd[0] == "gui":
gui = TKBook()
gui.root.mainloop()
print
print
示例2: save
# 需要导入模块: import Data [as 别名]
# 或者: from Data import save [as 别名]
def save(self):
"""
Save the current account to disk.
"""
Data.save(self.account_name, self.transaction_list)
示例3: Main
# 需要导入模块: import Data [as 别名]
# 或者: from Data import save [as 别名]
def Main():
if (not os.path.isdir(CONFIGDIR)):
os.mkdir(CONFIGDIR)
if (not os.path.isdir(SAVEDIR)):
os.mkdir(SAVEDIR)
planets = Data.loadPlanets(CONFIGDIR+"coords_planets.txt")
planet_names = list(planets.keys())
reservedwords = ["zone", "d", "help"] + planet_names
commands = Core.readconfigfile(CONFIGDIR+"words.ini")
#make sure that dictionnary contains all used keys and for all keys, each required subdictionnary is given
requiredkeys = {"map":[], "save":[], "target":["delallexplored","removeall"], "view":[], "exit":[], "set-terre":[]}
errmsg = ""
for key in requiredkeys:
if (key not in commands):
commands[key] = {"words":key}
errmsg += "- section "+key+" non trouvée\n"
elif ("words" not in commands[key]):
commands[key]["words"] = key
errmsg += "- aucun mot pour la commande "+key+"\n"
for subkey in requiredkeys[key]:
if (subkey not in commands[key]):
commands[key][subkey] = subkey
errmsg += "- paramètre manquant dans la commande "+key+": "+subkey+"\n"
#
#get set of words for each command (instead of space-separated string)
#keep only non reserved words, but at least one
for key in commands:
for subkey in commands[key]:
commands[key][subkey] = set(commands[key][subkey].split())
size = len(commands[key][subkey])
Core.removefromlist(commands[key][subkey], reservedwords)
if (len(commands[key][subkey]) != size):
if (subkey == "words"):
errmsg += "- des mots réservés ont été supprimés pour la commande "+key+"\n"
else:
errmsg += "- des mots réservés ont été supprimés pour le paramètre "+subkey+" dans la commande "+key+"\n"
if (len(commands[key][subkey]) == 0):
if (subkey == "words"):
commands[key][subkey].add(key)
errmsg += "- aucun mot pour la commande "+key+"\n"
else:
commands[key][subkey].add(subkey)
errmsg += "- paramètre manquant dans la commande "+key+": "+subkey+"\n"
#
#use some standard words to exit prompt
exitwords_reserved = ("quit", "exit")
for exit_word in exitwords_reserved:
if (not exit_word in commands["exit"]["words"]):
commands["exit"]["words"].add(exit_word)
#
if (len(errmsg) > 0):
printf("Problème(s) lors de la lecture du fichier words.ini:")
printf(errmsg)
playername = ""
if (len(sys.argv) >= 2):
playername = sys.argv[1].strip().lower()
if (Core.isforbidden(playername) or playername in exitwords_reserved):
playername = raw_input("Entrez votre pseudo: ")
playername = playername.strip().lower()
if (Core.isforbidden(playername)):
printf("Erreur: ce pseudo est interdit")
sys.exit(0)
elif (playername in exitwords_reserved):
sys.exit(0)
playerdata = Data.load(playername)
settings = playerdata[2]
if (playername not in settings):
settings[playername] = {}
settings = settings[playername]
if ("terre" in settings):
planet_names = addTerre(settings, settings["terre"].split(), planets)
Str = ""
Strlist = []
printf('Tapez "help" pour obtenir de l\'aide')
try:
exit = False
while (not exit and not Core.oneIn(commands["exit"]["words"], Strlist)):
Str = raw_input("> ").strip().lower()
if (Str == ""):
continue
Strlist = Str.split(" ")
try:
if (Core.oneIn(commands["exit"]["words"], Strlist)):
exit = True
if ("help" in Strlist):
print_help(Strlist, commands, planet_names, playername)
elif (Core.oneIn(commands["map"]["words"], Strlist)):
Map.makeMap(playername, playerdata, planets)
elif (Core.oneIn(commands["save"]["words"], Strlist)):
Data.save(playername, playerdata)
elif (Core.oneIn(commands["view"]["words"], Strlist)):
os.system(Map.getMapFilename(playername))
elif (Core.oneIn(commands["target"]["words"], Strlist) and not exit):
printf('Entrez vos nouveaux objectifs:')
while (not Core.oneIn(commands["exit"]["words"], Strlist)):
Str = raw_input("==> ").strip().lower()
if (Str == ""):
#.........这里部分代码省略.........