6

So an optional parameter expected in the web POST request of an API I'm using is actually a reserved word in python too. So how do I name the param in my method call:

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

this fails with a syntax error due to 'from' being a keyword. How can I pass this in in such a way that no syntax error is encountered?

citronic
  • 9,868
  • 14
  • 51
  • 74

2 Answers2

16

Pass it as a dict.

func(**{'as': 'foo', 'from': 'bar'})
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2
args = {'x':1, 'y':1, 'z':1, 'from':1}
example.webrequest(**args)

// dont use that library

khachik
  • 28,112
  • 9
  • 59
  • 94