473,387 Members | 1,779 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,387 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 1387
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Resant | last post by:
I have a query : Exec 'Select * From Receiving Where Code In (' + @pCode + ')' @pCode will contain more than one string parameter, eg : A1, A2, A3 How can i write that parameters, I try use :...
14
by: Dan | last post by:
Is it just me, or is the removal of support for the word "void" in a parameter list extremely annoying? Some of us have been programming for years putting "void function_name (void)" - and it...
25
by: Markus Svilans | last post by:
Hi, There seems to be some functionality missing from the STL. I am iterating through a linked list (std::list) using a reverse iterator and attempting to erase certain items from the list. It...
18
by: a | last post by:
can someone tell me how to use them thanks
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.