[Tutor] *args, **kargs as arguments

O.R.Senthil Kumaran orsenthil at gmail.com
Sat Nov 10 04:30:47 CET 2007


I know it can be a FAQ, but still I want ask to clarify my doubts and
assumptions.

I find usually in derived classes, a construct like this:

class Derived(BaseClass):
	def __init__(self, *args, **kargs):
		BaseClass.__init__(self, *args, **kargs)


- *args, **kargs passes a tuple and a dictionary to the BaseClass constructor.

My assumption is the BaseClass will always have a constructor that will
be receiving the tuple and a dictionary. Am I right?

Something of the sort.

class BaseClass:
	def __init__(self, atuple, adict):

I also found a construct something like this:

class URLopener:
	def __init__(self, proxies=None, **x509):

This is specifically from urllib.py where my doubts stem from.
Is the above construct still receiving a tuple and a dictionary?


Another doubt is, if we are not explicitly passing a dictionary, and the
dictionary is not a default argument, then is the dictionary values being passed through the namespace? 

I am scanning through the urllib.py code to understand the urlopen method and I am having the above doubts when trying to understand it. Please help.

Thank you.
-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org


More information about the Tutor mailing list