By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

**kw,**args what are these things ?

P: n/a
Hello !

I see these things in many sources, under wxPy:

def __init__(self,params,**kw,**args)

What are these parameters, and what's the meaning of the double * ?

Thanx for any info.

--
Best regards,
fowlertrainer mailto:fo***********@anonym.hu

PS:
Please send me private message, if possible, because I'm in digest
mode.
Thx
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <ma***************************************@python. org>,
<fo***********@anonym.hu> wrote:

I see these things in many sources, under wxPy:

def __init__(self,params,**kw,**args)

What are these parameters, and what's the meaning of the double * ?


First of all, when asking questions like this, please make sure to
cut'n'paste the text; I'm certain that isn't the code you were reading.

Second, read the docs. Start with the tutorial section on functions:
http://www.python.org/doc/current/tut/node6.html
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code --
not in reams of trivial code that bores the reader to death." --GvR
Jul 18 '05 #2

P: n/a
On Wed, 04 Feb 2004 10:59:13 +0100, fowlertrainer wrote:
I see these things in many sources, under wxPy:

def __init__(self,params,**kw,**args)

What are these parameters, and what's the meaning of the double * ?


Python functions can have positional arguments and keyword arguments;
if the *last* argument of a function begins with **, all extra keyword
arguments (i.e. those which do not match any of the parameter names of
the function) are put in a dictionary.

(The single * is used for passing a variable number of arguments.)

You will thus often see function definitions like the following:

def f(x, y, *args, **kw):
# the dictionary is kw

The following example should make this a little bit clearer:

def f(x, y, *args, **kw):
print x, y,

for i in args:
print i,

for k, v in kw.iteritems():
print k, v,

f(1, 2, 3, 4, five=5, six=6)

The output of this example is:

1 2 3 4 six 6 five 5

(Observe that dictionaries are not sorted!)

Remark: in your example, the ** is used two times; that is not
allowed (and does not make sense).

HTH / Nuff

Jul 18 '05 #3

P: n/a
Hello,
I see these things in many sources, under wxPy:

def __init__(self,params,**kw,**args)

What are these parameters, and what's the meaning of the double * ?

Try the tutorial. (Hint 4.7.2 Keyword Arguments and 4.7.3 Arbitrary Argument Lists).

HTH.
Miki
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.