473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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

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
3 2957
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Stefan Behnel | last post by:
Hi! I'm trying to do this in Py2.4b1: ------------------------------- import logging values = {'test':'bla'} logging.log(logging.FATAL, 'Test is %(test)s', values)...
10
by: Steven Bethard | last post by:
So, as I understand it, in Python 3000, zip will basically be replaced with izip, meaning that instead of returning a list, it will return an iterator. This is great for situations like: zip(*)...
27
by: TheDD | last post by:
Hello all, right now, i'm using the following macro to automatically add informations to exceptions: #define THROW(Class, args...) throw Class(__FILE__, __LINE__, ## args) but AFAIK, it's...
20
by: Ivar | last post by:
Hi, For my supprise I found that functions have 32 parameter limit. Where to find more info about this limitation or similar limitations ? I need at least 50, 100 would be ok. Real life...
17
by: ern | last post by:
I want to pass arguments to the main( ) function of my C program. Currently, I'm using main(char * args) But when I try to print args, I get an unhandled exception error. Is there a better,...
2
by: goodnamesalltaken | last post by:
Hello fellow python users, I've been working on a basic implementation of a privilege separated web server, and I've goto the point of running a basic cgi script. Basically when the execCGI...
1
by: xamman | last post by:
the handler declaration: CustomValidator1_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate ...
4
by: zslevi | last post by:
I've been reading the following example, and couldn't figure out, what **kw mean. (It's an empty dictionary, but what's the semantics): def wrap(method): def wrapped(self, *args, **kw): print...
5
by: Miki | last post by:
Hello All, I'm try to write the C equivalent of: def kw(*args, **kw): print "%d args" % len(args), if "default" in kw: print "default is %s" % kw else: print "no default"
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.