Say I have a master script that runs weekly via cronjob. This script imports a bunch of different functions from other Python files and runs their functions in sequence. I'd also like to be able to run a couple of the functions the master script runs but ad-hoc from the Terminal. What is the best way to construct both the master script and the individual files containing functions to be run? Example of current situation:
master_script.py
import do_bulk_things as b
import do_another_thing as a
b.do_first_bulk_thing()
b.do_second_bulk_thing()
if b.do_third_bulk_thing():
a.my_other_thing()
do_bulk_thinkgs.py
def do_first_bulk_thing():
# Code
def do_second_bulk_thing():
# Code
def do_third_bulk_thing():
# Code
if successful:
return True
do_another_thing.py
def my_other_thing():
# Code
If I want to run my_other_thing() without running the entire master_script.py, how and where should I be defining and calling everything? The imported files just have function definitions so I can't actually execute any function by running python do_another_thing.py
; and I also shouldn't execute the function my_other_thing() within do_another_thing.py because then it will run on import. It seems to me that I need to restructure things, but I need some best practices.