Is a Python named argument a keyword?

So the optional parameter expected in the web POST API request that I use is actually a reserved word in python. So, as I call the parameter in the method call:

example.webrequest(x=1,y=1,z=1,from=1) 

this fails with a syntax error due to the fact that "from" is a keyword. How to pass this in such a way that there is no syntax error?

+4
source share
2 answers

Pass it as a dict.

 func(**{'as': 'foo', 'from': 'bar'}) 
+13
source
 args = {'x':1, 'y':1, 'z':1, 'from':1} example.webrequest(**args) 

// do not use this library

+2
source

All Articles