Forum Discussion
Pass Python Variable as a query parameter in Advance Editor
- 7 years ago
My mistake, we lost the quitation marks. Try:
Source = Python.Execute( "import requests.. other code.... """ & MyVariable & """ .. other code.... "),
If this works I'll update the original answer.
You need end the string with " and append the parameter with the &
for example:
Source = Python.Execute( "import requests.. other code.... " & MyVariable & " .. other code.... "),
Power query will build eveything out as a string, and pass that to python. so the " & MyVariable & " .
It reall breaks it down into three strings ...
"import requests.. other code.... " & MyVariable & " .. other code.... "
First string, your variable string, and the end string. The & is a concatenate and concatenates the strings, which it then passes as one big string to python.
Dear SteveCampbell ,
First of all, Thank you for your reply.
I followed the same procedure as you mentioned.
But encountering below error :
DataSource.Error: ADO.NET: Python script error.
File "PythonScriptWrapper.PY", line 91
start=2019/05/17 06:29
^
SyntaxError: invalid token
Details:
DataSourceKind=Python
DataSourcePath=Python
Message=Python script error.
Screenshot for your reference :
- SteveCampbell7 years agoMemorable Member
This is a python error, in that you should not have leading 0s in your date.
2019/05/17 06:29
Maybe you should use the datetime library:
datetime.datetime(2019, 5, 17, 6, 29)- Amir8517 years agoHelper I
Hi SteveCampbell ,
Cant we pass it as a string like "2019/05/17 06:29" as a parameter instead of Datetime.
Because I run the same script in Jupyter notebook. It was working fine there without any issue.
Thanks
Amir
- SteveCampbell7 years agoMemorable Member
My mistake, we lost the quitation marks. Try:
Source = Python.Execute( "import requests.. other code.... """ & MyVariable & """ .. other code.... "),
If this works I'll update the original answer.