Gerges
Gerges

Reputation: 6519

Passing command line arguments from a folder script to a file script

I have the following folder and files:

script_folder
|__   __main__.py
|__   script1.py
|__   script2.py

The file __main__.py allows running the folder as a script, so I can do something like: python3 script_folder. Also, script1.py and script.py are scripts each having different command line arguments. My goal is to be able to run the folder script as such:

    python3 script_folder script1 --normalize -o output.txt

where the positional argument (script1) tells folder_script to run script1.py and the options --noramlize and -o are options specific for script1.py. What is the best way to run the correct script and pass along the command line arguments to the correct file script from __main__.py folder script?

Note: I am using argparse to parse the arguments in each file script.

Upvotes: 1

Views: 53

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799520

Don't. Call the script directly (after making script_folder a package, if required).

python3 -m script_folder.script1 --normalize -o output.txt

Upvotes: 2

Related Questions