0
Public Sub Run_Calibrate(sector As String)
Dim runString As String
Dim kwargs As String


kwargs = "{" & "'pd_grade_o':" & "[" & _
                   pd_array(0) & ", " & pd_array(1) & ", " & pd_array(2) & ", " & _
                   pd_array(3) & ", " & pd_array(4) & ", " & pd_array(5) & ", " & _
                   pd_array(6) & ", " & pd_array(7) & ", " & pd_array(8) & ", " & _
                   pd_array(9) & ", " & pd_array(10) & ", " & pd_array(11) & "], " & _
              "'ue_rate_6_o':" & "[" & _
                   ue_rate_6_o(0) & ", " & ue_rate_6_o(1) & ", " & ue_rate_6_o(2) & ", " & _
                   ue_rate_6_o(3) & ", " & ue_rate_6_o(4) & ", " & ue_rate_6_o(5) & ", " & _
                   ue_rate_6_o(6) & ", " & ue_rate_6_o(7) & ", " & ue_rate_6_o(8) & ", " & _
                   ue_rate_6_o(9) & ", " & ue_rate_6_o(10) & ", " & ue_rate_6_o(11) & "], " & _
              "'sbli_yoy_o':" & "[" & _
                   sbli_yoy_o(0) & ", " & sbli_yoy_o(1) & ", " & sbli_yoy_o(2) & ", " & _
                   sbli_yoy_o(3) & ", " & sbli_yoy_o(4) & ", " & sbli_yoy_o(5) & ", " & _
                   sbli_yoy_o(6) & ", " & sbli_yoy_o(7) & ", " & sbli_yoy_o(8) & ", " & _
                   sbli_yoy_o(9) & ", " & sbli_yoy_o(10) & ", " & sbli_yoy_o(11) & "], " & _
              "'nfpr_6_o':" & "[" & _
                   nfpr_6_o(0) & ", " & nfpr_6_o(1) & ", " & nfpr_6_o(2) & ", " & _
                   nfpr_6_o(3) & ", " & nfpr_6_o(4) & ", " & nfpr_6_o(5) & ", " & _
                   nfpr_6_o(6) & ", " & nfpr_6_o(7) & ", " & nfpr_6_o(8) & ", " & _
                   nfpr_6_o(9) & ", " & nfpr_6_o(10) & ", " & nfpr_6_o(11) & "], "

kwargs = kwargs & _
         "'60':" & "[" & _
         w_60(0) & ", " & w_60(1) & ", " & w_60(2) & "], " & _
         "'90':" & "[" & _
         w_90(0) & ", " & w_90(1) & ", " & w_90(2) & "], " & _
         "'120':" & "[" & _
         w_120(0) & ", " & w_120(1) & ", " & w_120(2) & "], " & _
         "'150':" & "[" & _
         w_150(0) & ", " & w_150(1) & ", " & w_150(2) & "], " & _
         "'180':" & "[" & _
         w_180(0) & ", " & w_180(1) & ", " & w_180(2) & "]}"

Debug.Print kwargs
runString = Chr(34) & "import DQforecast; DQforecast.calibrate('" & sector & "', " & kwargs & ")" & Chr(34)
Debug.Print runString


RunPython (runString)

End Sub

xlwings 可以处理在方法调用中传递的 kwargs 吗?我得到一个

File "<string>", line 1 
invalid syntax

我已经配置了我的 xlwings 设置,以便 PYTHON_WIN 和 PYTHON_PATH 是正确的,并且我已经成功地运行了没有来自 xlwings 参数的函数。

4

1 回答 1

0

根据文档,是的。

您的代码的问题反映在语法突出显示本身中。RunPython您没有在call的右括号之前关闭字符串。以下代码应该可以工作:

Sub test()
RunPython("import DQforecast; DQforecast.calibrate('OP Dealer')")
end Sub
于 2015-03-02T07:34:16.367 回答