473,382 Members | 1,204 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,382 software developers and data experts.

**kwargs?

All your **kwargs are belong to us.

*args is documented in the Tutorial. I reckon **kwargs represents a
dictionary of arguments. But I don't quite get the semantics of **x.
Undefined length tuple of undefined length tuples? Are there other
practical use cases for ** (common enough please, I wish I was, but I'm
not a scientist).

TIA,
Francois
Jul 21 '05 #1
4 3203
Francois De Serres wrote:
All your **kwargs are belong to us.

*args is documented in the Tutorial. I reckon **kwargs represents a
dictionary of arguments. But I don't quite get the semantics of **x.
Undefined length tuple of undefined length tuples? Are there other
practical use cases for ** (common enough please, I wish I was, but I'm
not a scientist).

TIA,
Francois

Assume d = { 'arg1':'value1','arg2':'value2' }. Then

func(**d)

is the same as:

func(arg1='value1', arg2='value2')

HtH, Roland
Jul 21 '05 #2
Francois De Serres wrote:
All your **kwargs are belong to us.

*args is documented in the Tutorial. I reckon **kwargs represents a
dictionary of arguments. But I don't quite get the semantics of **x.
Undefined length tuple of undefined length tuples? Are there other
practical use cases for ** (common enough please, I wish I was, but I'm
not a scientist).


Where did you get "tuples of tuples" for **x ? It doesn't have tuples
at all, but is merely a dictionary, as you said in the first place. Are
you implying you think **kwargs and **x are somehow magically different?

-Peter
Jul 21 '05 #3
Peter Hansen wrote:
Francois De Serres wrote:

*args is documented in the Tutorial. I reckon **kwargs represents a
dictionary of arguments. But I don't quite get the semantics of **x.
Undefined length tuple of undefined length tuples? Are there other
practical use cases for ** (common enough please, I wish I was, but
I'm not a scientist).


Where did you get "tuples of tuples" for **x ?


I would guess it is confusion from languages where unary * means
dereference and ** means double dereference.

To the OP: I'm glad you have been reading the tutorial. If you have
further questions the reference manual is a good place to look:

http://docs.python.org/ref/function.html

Just as you can use a name other than self as the first argument to an
unbound method, you can call your *args and **kwargs *x and **y instead,
but they will still act just like *args and **kwargs.

The stars are magic, not the names.
--
Michael Hoffman
Jul 21 '05 #4
Michael Hoffman wrote:
Peter Hansen wrote:

Francois De Serres wrote:


*args is documented in the Tutorial. I reckon **kwargs represents a
dictionary of arguments. But I don't quite get the semantics of **x.
Undefined length tuple of undefined length tuples? Are there other
practical use cases for ** (common enough please, I wish I was, but
I'm not a scientist).

Where did you get "tuples of tuples" for **x ?


I would guess it is confusion from languages where unary * means
dereference and ** means double dereference.

That was precisely my mistake.
To the OP: I'm glad you have been reading the tutorial. If you have
further questions the reference manual is a good place to look:

http://docs.python.org/ref/function.html

Now I see, there's a '**' token, which is not the same as two adjacents
'*' tokens.
Just as you can use a name other than self as the first argument to an
unbound method, you can call your *args and **kwargs *x and **y instead,
but they will still act just like *args and **kwargs.

The stars are magic, not the names.

Thanks mucho!
F.

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Achim Domma | last post by:
Hi, I'm using py2exe to create a exe out of a python script. If works fine so far, but a get lot's of this warnings: warning: use func(*args, **kwargs) instead of apply(func, args, kwargs) ...
2
by: Jim Jewett | last post by:
Normally, I expect a subclass to act in a manner consistent with its Base classes. In particular, I don't expect to *lose* any functionality, unless that was the whole point of the subclass. ...
26
by: lbolognini | last post by:
Hi all, I have a very long list of parameters coming from a web form to my method foo(self, **kwargs) I would like to avoid manually binding the variables to the values coming through the...
4
by: tzellman | last post by:
Ok, so here is my situation: Let's assume I have a function that makes good use of the kwargs parameter. It requires that there is a certain "format" for the kwargs keywords. (I am using Django,...
2
by: johnny | last post by:
What is **kwargs mean in python? When you put double **, does it mean passing by reference? For example: def redirect_to(request, url, **kwargs):
5
by: JonathanB | last post by:
Ok, this is probably definitely a newbie question, but I have looked all over the Python library reference material and tutorials which I can find online and I cannot find a clear definition of...
13
by: dmitrey | last post by:
I need something like this: def func1(*args, **kwargs): if some_cond: return func2(*args, **kwargs) else: return func3(some_other_args, **kwargs) Thank you in advance, D.
1
by: dmitrey | last post by:
hi all, howto check is function capable of obtaining **kwargs? i.e. I have some funcs like def myfunc(a,b,c,...):... some like def myfunc(a,b,c,...,*args):... some like
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.