gpt4 book ai didi

python - 将参数从批处理文件发送到 Python 脚本

转载 作者:太空狗 更新时间:2023-10-29 21:44:08 25 4
gpt4 key购买 nike

我在 Win XP 上运行 Python 3.2。我通过批处理文件运行 python 脚本:

C:\Python32\python.exe test.py %1

%1 是我传递给在 python 脚本中进行一些处理的参数。

批处理文件中有 2 个变量,我也想将它们作为参数发送给 python 脚本。

设置 $1=hey_hi_hello

设置 $2=hey_hi

如果可能的话,我希望能够做这样的事情:

C:\Python32\python.exe test.py %1 $1 $2

然后通过 sys.argv[2]sys.argv[3]

在 python 脚本中检索这些参数

如果有任何帮助,我们将不胜感激。谢谢。

最佳答案

你的脚本.bat:

set VAR_1=this
set VAR_2=that

python your_script.py %1 %VAR_1% %VAR_2%

关于python - 将参数从批处理文件发送到 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10823033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com