Python function argument of predicate type a=b
Pardon my Python skill or the lack of it. I saw some methods calls of the form
auth_req =开发者_JAVA技巧 urllib2.Request(auth_uri, data=authreq_data)
If I put in just authreq_data
I get an error. What is the correct technical definition for this type of method argument? Is it a boolean/predicate type?
They're called keyword arguments.
You can use them without specifying the keyword, so long as you also pass all the arguments before them.
The signature of urrlib2.Request is
urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable])
So as long as you specify the url, auth_uri
in this case, you should be able to pass authreq_data
without specifying that it is the data
argument.
auth_req = urllib2.Request(auth_uri, authreq_data)
Python 3 has also added a syntax for specifying keyword only arguments.
It's a keyword argument.
精彩评论