What does "*list" mean?

G

Greg Smethells

What exactly does "*values" mean in the following code? Is this a
pointer to a PyList? Why can I not find good documentation on this any
where? I must be blind:
from struct import *
format = "dl"
values = [3.14, 42]
foo = pack(format, *values)
foo '\x1f\x85\xebQ\xb8\x1e\t@*\x00\x00\x00'
unpack(format, foo) (3.1400000000000001, 42)

More importantly still, how would you write the same code in C? If you
wanted to instead call struct_pack(PyObject *tuple), what would the
tuple look like in C?

Thanks to anyone who can clear all this up for me.

Greg
 
D

Diez B. Roggisch

Greg said:
What exactly does "*values" mean in the following code? Is this a
pointer to a PyList? Why can I not find good documentation on this any
where? I must be blind:

Just two days ago I had the same qustion, and I got this as answer from
Raymond Hettinger:

http://www.python.org/dev/doc/devel/ref/calls.html

Regarding your C question: I didn't do such a thing, but *list only makes
the items of list be used as distinct arguments - so its more a matter of
the function signature you're calling. I'm sure you'll find something about
variable list arguments somewhere - that means that you function looks like
this:

def foo(arg1, arg2, *args):
....

Diez
 
G

Greg Brunet

Raymond Hettinger said:
Hmm, it sounds like the *args calling format
needs to be added to the tutorial.


Raymond Hettinger

And also added to the index of the reference manual! I remember trying
to figure it out the first time that I ran into it - it's pretty
frustrating to not be able to look up these kinds of 'special' symbols.

-- Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top