Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 = 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?

like image 981
Wangwang Avatar asked Jun 21 '26 20:06

Wangwang


1 Answers

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.

like image 58
agf Avatar answered Jun 24 '26 11:06

agf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!