【发布时间】:2019-01-13 09:28:24
【问题描述】:
我在 python 3.7 中有这个脚本:
pars = argparse.ArgumentParser(prog='copy dirs script', description="à copier MSRE localment:",
epilog="Comme ça on copie les repertoires")
pars.add_argument("-o", "--output", action='store_const', default=destination_file,
const=destination_file1,
help="the destination dirctory is the curently working dirctory")
pars.add_argument("-a", "--arch", choices=("all", "i386", "x86_64"), type = lambda s : s.lower(),
help="Targeted check architecture: 32b, 64b, All")
pars.add_argument("-p", "--platform", choices=("all", "windows", "linux"), type = lambda s : s.lower(),
help="Targeted check platform: Windows, Linux, All")
args = pars.parse_args()
我想在命令行解析输出,例如:
python script.py -o C:/Users/michael/Documents/install -a all -p windows
我不知道如何将输出存储到变量中。 我该如何继续?
【问题讨论】:
-
您想将哪个输出存储到变量中?当你调用
--help时这个程序的输出?程序本身的输出?命令行输入?除非您更具体地说明您需要我们做什么,否则我认为我们无法提供帮助。 -
我想将我给程序的路径存储到一个变量中 python script.py -o C:/Users/michael/Documents/install -a all -p windows, C:/当我运行程序时将用户/迈克尔/文档/安装存储到变量中
标签: python python-3.x file path argparse