471,337 Members | 1,017 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

parameter list notation

I am trying to use a database written in Python called buzhug.

In looking at some of the functions I see this prototype:

def create(self,*fields,**kw):

I am not clear on what the * and the ** are for or what they
represent. Or, what are they referred to as so I can do a query for
information on them.

Thanks
TFD

Sep 4 '07 #1
9 1320
Well I did a search on "Python variable length arguments" and found a
hit that seems to explain the *fields parameter:

When you declare an argment to start with '*', it takes the argument
list into an array.

def foo(*args):
print "Number of arguments:", len(args)
print "Arguments are: ", args
Sep 4 '07 #2
TheFlyingDutchman wrote:
Well I did a search on "Python variable length arguments" and found a
hit that seems to explain the *fields parameter:

When you declare an argment to start with '*', it takes the argument
list into an array.

def foo(*args):
print "Number of arguments:", len(args)
print "Arguments are: ", args

Well done. The ** notation allows you to collect arbitrary keyword
arguments into a dictionary (whose name is kw in the example you gave).
With such a formal parameter any keyword argument is acceptable for a
call (unless it duplicates a key value).

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Sep 4 '07 #3
TheFlyingDutchman <zz******@aol.comwrote:
I am trying to use a database written in Python called buzhug.

In looking at some of the functions I see this prototype:

def create(self,*fields,**kw):

I am not clear on what the * and the ** are for or what they
represent. Or, what are they referred to as so I can do a query for
information on them.
You could try searching for 'function definitions'. That might lead you to
http://docs.python.org/ref/function.html "Python Reference Manual, 7.6
Function definitions":
Function call semantics are described in more detail in section 5.3.4.
A function call always assigns values to all parameters mentioned in
the parameter list, either from position arguments, from keyword
arguments, or from default values. If the form ``*identifier'' is
present, it is initialized to a tuple receiving any excess positional
parameters, defaulting to the empty tuple. If the form
``**identifier'' is present, it is initialized to a new dictionary
receiving any excess keyword arguments, defaulting to a new empty
dictionary.
Sep 4 '07 #4
Steve, Ben, Duncan,

Thanks for the replies.

TFD
Sep 4 '07 #5
On Mon, 03 Sep 2007 22:00:28 -0700, TheFlyingDutchman wrote:
I am trying to use a database written in Python called buzhug.

In looking at some of the functions I see this prototype:

def create(self,*fields,**kw):

I am not clear on what the * and the ** are for or what they represent.
Or, what are they referred to as so I can do a query for information on
them.
And yet you're making your own fork of Python.

Good luck with that! Do let us know how it works out for you.

For the record, your question is answered in the FAQ:
http://www.python.org/doc/faq/programming/

and in the tutorial:
http://docs.python.org/tut/node6.html

--
Steven.
Sep 4 '07 #6
On Mon, 03 Sep 2007 22:10:41 -0700, TheFlyingDutchman wrote:
Well I did a search on "Python variable length arguments" and found a
hit that seems to explain the *fields parameter:

When you declare an argment to start with '*', it takes the argument
list into an array.
No it doesn't.
>>def test(*args):
.... import array
.... assert type(args) is array.array, "Not an array"
....
>>test(1, 2, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in test
AssertionError: Not an array


--
Steven.
Sep 4 '07 #7
On Sep 4, 1:53 pm, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.auwrote:
On Mon, 03 Sep 2007 22:10:41 -0700, TheFlyingDutchman wrote:
Well I did a search on "Python variable length arguments" and found a
hit that seems to explain the *fields parameter:
When you declare an argment to start with '*', it takes the argument
list into an array.

No it doesn't.
>def test(*args):

... import array
... assert type(args) is array.array, "Not an array"
...>>test(1, 2, 3)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in test
AssertionError: Not an array
Oh, I forgot the context of the discussion! As you are well aware, my
Python fork() (which I am now calling PIEthun 3.01 in beta and PIEthun
3000 upon release) has made a few changes. Tuples are known as arrays.
Lists are known as uarrays (for updatable array) and the array module
has been renamed to homo_uarray (homogenous_updatable_array was just
too much typing).

In the future I will be sure to specify the context of my statements -
whether PIEthunic or Pythonic in nature.
Sep 4 '07 #8
TheFlyingDutchman wrote:
On Sep 4, 1:53 pm, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.auwrote:
>On Mon, 03 Sep 2007 22:10:41 -0700, TheFlyingDutchman wrote:
>>Well I did a search on "Python variable length arguments" and found a
hit that seems to explain the *fields parameter:
When you declare an argment to start with '*', it takes the argument
list into an array.
No it doesn't.
>>>>def test(*args):
... import array
... assert type(args) is array.array, "Not an array"
...>>test(1, 2, 3)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in test
AssertionError: Not an array

Oh, I forgot the context of the discussion! As you are well aware, my
Python fork() (which I am now calling PIEthun 3.01 in beta and PIEthun
3000 upon release) has made a few changes. Tuples are known as arrays.
Lists are known as uarrays (for updatable array) and the array module
has been renamed to homo_uarray (homogenous_updatable_array was just
too much typing).

In the future I will be sure to specify the context of my statements -
whether PIEthunic or Pythonic in nature.

Perhaps you could move further discussions to comp.lang.piethun?

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Sep 4 '07 #9
>
Perhaps you could move further discussions to comp.lang.piethun?
Fair enough. Will contain PIEthun discussion to the PIEthun mailing
list and the aforementioned newsgroup once it is established.

It suddenly dawned on me while rereading my defense of my use of the
term "array" .... that I wasn't the person who used array.

That came from here and was probably written by someone who has a lot
of experiences in languages other than Python:

http://snippets.dzone.com/posts/show/1713

Sep 5 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Dan | last post: by
25 posts views Thread by Markus Svilans | last post: by
18 posts views Thread by a | last post: by
reply views Thread by rosydwin | last post: by

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.