从 VBA 传递 Python 脚本参数 [英] Passing Python Script parameter from VBA
本文介绍了从 VBA 传递 Python 脚本参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 VBA 代码:
I have the following VBA code:
Private Sub cmdLoadSalaries_Click()
args = "C:\Users\Cole\Documents\Visual Studio 2010\Projects\pyFanDuel\pyFanDuel\pyFanDuel.py " & Me.txtUrl
Debug.Print args
Call Shell("C:\python27\python.exe " & args)
End Sub
脚本在没有Me.txtUrl"参数的情况下运行良好,但失败了.
The script runs fine without the "Me.txtUrl" argument, but fails with it.
在 python 脚本中,我将一个变量设置为 argv[1]即 PassedVariable = str(sys.argv[1])
In the python script I set a variable to argv[1] ie PassedVariable = str(sys.argv[1])
但是脚本无法运行.
任何帮助都会很棒,谢谢大家.
Any help would be great, thanks all.
推荐答案
为了能够因为给出正确"的答案而获得赞誉,我将重复我上面所说的(以及你确认的):将参数放在双引号中以正确转义"所有通过 DOS shell 传递的奇怪字符.
In order to be able to get credit for giving the "right" answer, I will repeat what I said above (and what you confirmed): Put the argument in double quotes to "properly escape" all those strange characters as they are passed through the DOS shell.
这篇关于从 VBA 传递 Python 脚本参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文