将批处理文件中的参数发送到 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%