I am running in a loop an astronomical script written by another person. This is a minimal version of my loop:
from astro_script_file import some_astro_class
for file_name in ['file_1.txt', 'file_2.txt', 'file_n.txt']:
some_astro_class.function_1(file_name)
When executing the above function_1 makes calculations based on the input txt-file and prints an output to the screen of the kind number of populated galaxies: some-number. The number of galaxies is declining with each iteration of my loop and I want to break the loop when the number reaches 0. For that I need to somehow read in the print statement or load it into a variable. I don't want to alter the astronomical script itself that I am provided with, instead I want to tinker only outside of it when I am executing the script.
Is this possible? Is there some way to load print statements when they get executed?
function_1handle this case? I don't have more info but I imagine it will run forever without it.function_1? reading the output seems like overkill compare to simply returning the number, and I don't know how you are going to save the number in a variable without editing the script.function_1doesn't handle the case of galaxy counts, it just spits them out. It's becausefunction_1was not intended by the author to be be used in a loop. Even I most of the time don't use it in a loop. But for a special task now I have to. And the loop doesn't run forever, it runs until all files that I provide are covered