无法将“.bat”文件中的参数传递给 python 脚本

问题描述

我正在尝试从我的 .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: 列表索引超出范围

解决方法

变量名和等号之间的空格成为名称的一部分,后面的空格成为值的一部分。摆脱空白:

set fileDestination="\home\a\.."
set fileLocation="\home\b\.."
set fileName="myFile.xlsx"