将批处理文件中的参数发送到 Python 脚本 [英] Sending arguments from Batch file to Python script
本文介绍了将批处理文件中的参数发送到 Python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Win XP 上运行 Python 3.2.我通过这个批处理文件运行 python 脚本:
I'm running Python 3.2 on Win XP. I run a python script thru a batch file via this:
C:Python32python.exe test.py %1
%1
是我传递的参数,用于在 python 脚本中进行一些处理.
%1
is an argument that i pass to do some processing in the python script.
我在批处理文件中有 2 个变量,我也想将它们作为参数发送给 python 脚本.
I have 2 variables in the batch file that I also want to send as arguments to the python script.
set $1=hey_hi_hello
set $2=hey_hi
如果可能的话,我希望能够做这样的事情:
I want to be able to do something like this if possible:
C:Python32python.exe test.py %1 $1 $2
然后通过sys.argv[2]
和sys.argv[3]
非常感谢您对此的任何帮助.谢谢.
Would appreciate any help with this. Thank you.
推荐答案
your_script.bat:
your_script.bat:
set VAR_1=this
set VAR_2=that
python your_script.py %1 %VAR_1% %VAR_2%
这篇关于将批处理文件中的参数发送到 Python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文