What does "*list" mean?

Discussion in 'Python' started by Greg Smethells, Jul 31, 2003.

  1. 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
    Greg Smethells, Jul 31, 2003
    #1
    1. Advertising

  2. Greg Smethells wrote:

    > 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
    Diez B. Roggisch, Jul 31, 2003
    #2
    1. Advertising

  3. Greg Smethells

    Greg Brunet Guest

    "Raymond Hettinger" <> wrote in message
    news:mfiWa.308$W%...
    > 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
    Greg Brunet, Aug 1, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pratip Mukherjee

    Help: what does this VHDL code mean?

    Pratip Mukherjee, Jun 22, 2005, in forum: VHDL
    Replies:
    16
    Views:
    1,259
    Kim Enkovaara
    Jun 27, 2005
  2. dackz
    Replies:
    0
    Views:
    476
    dackz
    Feb 6, 2007
  3. Li Ma
    Replies:
    1
    Views:
    2,264
    Roedy Green
    Mar 9, 2009
  4. Rahul
    Replies:
    4
    Views:
    548
    Robert Kern
    Apr 7, 2009
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,178
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page