【发布时间】:2018-10-21 06:49:42
【问题描述】:
所以我尝试通过使用 dict 来选择要运行的函数来减少嵌套的 if。在测试中调用执行时,我通常使用 "execute("BACKUP","/home/src","/home/dest")" 调用它
但由于某种原因,它同时运行了两次 BACKUP 选项。我究竟做错了什么?我正在使用 Python3
def execute(jobtype, src, dst):
if jobtype == "FULL":
_o_src = fs.Index(src)
fs.MakeFolders(_o_src.GetFolders(), dst)
fs.MakeFiles(src, dst, _o_src.GetFiles())
if jobtype == "INCREMENTAL":
print("DO INCREMENTAL BACKUP " + src + " TO " + dst)
# Do the things
options = {
"BACKUP": execute(self.jobtype, self.src, self.dst),
"RESTORE": execute(self.jobtype, self.dst, self.src),
}
options[jobtype]()
【问题讨论】:
-
...因为您要调用它两次...
-
好吧,对于初学者来说,不要调用函数...
标签: python python-3.x function dictionary