0

I have a python script "Script1.py" that I do not change the inside of. I want to interact with its output using another script(.py or .bat). The script "Script1.py" gives a lot of options with print(), and I should choose each time.

So, is there a way to read his output and send him the right options that I need with another script?

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
Sevij
  • 1
  • 1
    Does this answer your question? [Running shell command and capturing the output](https://stackoverflow.com/questions/4760215/running-shell-command-and-capturing-the-output) – mkrieger1 Aug 30 '21 at 09:26

1 Answers1

2

Put the code inside a function and call it with an import. Also, you can use if __name__ == '__main__' to execute the module as an script.

def function_generic_name(arg1,arg2):
    **code**
    return something

if __name__ == '__main__':
    function_generic_name(arg1,arg2)
Fran Arenas
  • 639
  • 6
  • 18