将argparse bash脚本转换为python脚本
考虑下面的bash脚本。脚本argparse_test.py是一个具有各种变量的argparse脚本。
python -u argparse_test.py \
--is_training 3 \
--root_path ./dataset/ \
--data_path data.csv \
-/test_$seq_len'_'196.log
我如何将此bash脚本转换为python脚本,以便我可以在带有各种变量的python iDE中运行它?
Consider the bash script below. The script argparse_test.py is an argparse script with various variables.
python -u argparse_test.py \
--is_training 3 \
--root_path ./dataset/ \
--data_path data.csv \
-/test_$seq_len'_'196.log
How would I convert this bash script to a python script so that I could run it in a python IDE with the various variables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此
bash
输入应产生
sys.argv
,看起来这是一个粗略的猜测; bash可能正在处理斜线不同(我现在在Windows机器上)。
“在IDE中运行”是一个模糊的请求。
某些IDE具有
运行
菜单项,以及指定命令行参数的方法(通常在单独的菜单设置项目中)。如果您的代码设置了解析器:
该行
读取
sys.argv [1:]
并解析它。因此,使用解析器的另一种方法是直接提供等效的字符串列表:如果您可以修改脚本,则可以添加几个显示
,然后在
parse_args
args
将是argparse.namespace
应像dict
具有相同键的dict
的对象,并值任何具有相同属性的Python对象都应与
在您的代码其余部分中,args 。
我觉得这个答案太长而详细 - 因为这个问题的模糊性。
This
bash
inputshould produce a
sys.argv
that looks likethat's a rough guess; bash may be handling the slashes different (I'm on a windows machine now).
"running in an IDE" is a vague request.
Some IDE have a
run
menu item, and a way of specifying commandline arguments (usually in a separate menu setup item).If you have code that setups up a parser:
the line
reads that
sys.argv[1:]
and parses it. So an alternative way to use the parser is to provide the equivalent list of strings directly:If you can modify the script, you could add a couple of displays
and after the
parse_args
args
will be aargparse.Namespace
object that should display likeis a
dict
with the same keys and valuesAny python object with the same attributes should be have the same as
args
in the rest of your code.I have a feeling this answer is too long and detailed - because of the vagueness of the question.