[英]Pass directory to python script as command line argument
I have a few sub-directories that live in the same folder as my python script.我有一些子目录与我的 python 脚本位于同一文件夹中。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.