Quite often I do an anlysis with certain settings and store the plots or results in a folder which is separated from the codebase. To keep track of chosen settings I save the script like so:
import MyClass as my
model = my(some_parameters)
model.run()
with open(os.path.join(save_path, 'used_script_for_docu.py'), 'w') as copied_script_file:
with open(os.path.abspath(__file__), 'r') as script_file:
script_content = script_file.read()
copied_script_file.write(script_content)
Is it somehow possible to add a function to MyClass which can save the script file like explained above? Can the instance of MyClass (model
) somehow acces the script file with the current parameters settings? Or are there any other methods to save the script automatically without having to type/copy the lines from above from script to script?
EDIT: I would prefer to store the script file and not the states/parameters of the model because the script might contain settings/procedures which were not anticipated in beforehand and can threfore not be saved automatically from the namespace of e.g. model