When automating multi-step batch operations in Python, you can define a list of function references paired with argument tuples and iterate through them sequentially:
from functions import *
def main():
functions = [
(BackupDB, (backupname, dbtype)),
(ZipBackup, (backupname,)),
(RemoveOldBackups, ())
]
for func, args in functions:
result = func(*args)
function_name = func.__name__
if result == 0:
print(f"{function_name} step has been completed successfully.")
else:
print(f"{function_name} step encountered errors. Execution halted.")
return
if __name__ == "__main__":
main()
By packaging arguments as tuples (arg1, arg2), func(*args) unpacks them cleanly. For functions requiring no arguments, simply pass an empty tuple ().