【发布时间】:2021-02-24 02:32:50
【问题描述】:
我正在尝试从我的 .bat 文件运行 python 脚本,但我无法传递参数。请在下面找到我的代码:
.bat 文件
set fileDestination = "\home\a\.."
set fileLocation = "\home\b\.."
set fileName = "myFile.xlsx"
"C:\Swdtools\Python3.6.3 X64\Python" fileTransfer.py %fileDestination% %fileLocation% %fileName%
文件传输.py
import sys
print(sys.argv[2])
上面的打印语句给了我
IndexError: 列表索引超出范围
【问题讨论】:
-
print(sys.argc)应该提供一些细节。 -
去掉
set语句中=周围的空格。 -
你真的要在变量的值中加上引号吗?
标签: python-3.x windows batch-file argv