【发布时间】:2015-09-01 15:53:24
【问题描述】:
我有一个非常简单的 VBA 脚本,它将运行一个 Python 脚本,该脚本具有指定的参数(它们是文件夹路径,包含空格)。
代码如下
Dim path As String
path = Left(pdocinfo.path, InStrRev(pdocinfo.path, "\")) ' e.g C:\Temp\City Addresses
Dim pyLocation As String
pyLocation = "C:\Temp\filePath.py"
Dim strReports As String
strReports = path & "Reports\"
Dim strImages As String
strImages = path & "Images\"
Dim shellvar As Long
shellvar = shell("C:\Python26\ArcGIS10.0\python.exe " & pyLocation & " " & path & " " & strImages & " " & strReports , vbNormalFocus)
但是,当 Python 脚本运行时,文件路径(strImages、strReports 和 path)无法正确解析,因为它们在文件夹路径中包含空格。
Python 解释多个作为动态变量且还包含空格的参数的正确方法是什么?
编辑: 从下面的评论开始,我尝试了以下方法
shellvar = Shell("C:\Python27\ArcGIS10.2\python.exe " & pyLocation & " " & """" & path & """" & " " & """" & strImages & """" & " " & """" & strReports & """", vbNormalFocus)
我想要的结果是
Argument 0: C:\Temp\filePath.py
Argument 1: "C:\Temp\City Addresses"
Argument 2: "C:\Temp\City Addresses\Images"
Argument 3: "C:\Temp\City Addresses\Reports"
【问题讨论】:
-
你可能不得不用双引号括起来。 & """" & strImages & """" & 有四个双引号产生一个双引号。