I have a few sub-directories that live in the same folder as my python script. I am trying to run the script inside one of the sub-directories.
example:
$ script.py subdirectory
Is there a way to pass in the sub directory at command line
I have a few sub-directories that live in the same folder as my python script. I am trying to run the script inside one of the sub-directories.
example:
$ script.py subdirectory
Is there a way to pass in the sub directory at command line
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-subdir", "--subdirectory", help="enter subdirectory name")
params = parser.parse_args()
subdir = params.subdirectory
## and continue your code using subdir as the used subdirectory name
So when you want to run:
script.py -subdir SUBDIRECTORY_NAME_HERE