geoffroychaussonnet / script_to_monitor_Covid19

Python scripts to monitor Covid-19
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Extract initialisation out of `main` function #19

Closed jferard closed 4 years ago

jferard commented 4 years ago
def main(param1, param2, param3):
    script here.

if __name__ == "__main__":
    param1 = ...
    # param1 = ...

    param2 = ...
    param3 = ...
    main(param1, param2, param3)

Is more flexible than:

def main():
    param1 = ...
    # param1 = ...

    param2 = ...
    param3 = ...
    ################ Parameters to define manually (END) ######################

    script here.

if __name__ == "__main__":
    main()

Because the function main may be imported into another script and called with other parameters (e.g. loaded from file):

from plot_... import main as plot1

param_by_name = load_from_file()
plot1(**param_by_name)