开发者

Python Named Argument is Keyword?

开发者 https://www.devze.com 2023-01-25 05:35 出处:网络
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开发者_Python百科 my method call:

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开发者_Python百科 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?


Pass it as a dict.

func(**{'as': 'foo', 'from': 'bar'})


args = {'x':1, 'y':1, 'z':1, 'from':1}
example.webrequest(**args)

// dont use that library

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号