What does "*list" mean?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Smethells

    #1

    What does "*list" mean?

    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:
    [color=blue][color=green][color=darkred]
    >>> from struct import *
    >>> format = "dl"
    >>> values = [3.14, 42]
    >>> foo = pack(format, *values)
    >>> foo[/color][/color][/color]
    '\x1f\x85\xebQ\ xb8\x1e\t@*\x00 \x00\x00'[color=blue][color=green][color=darkred]
    >>> unpack(format, foo)[/color][/color][/color]
    (3.140000000000 0001, 42)[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

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

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

    Greg
  • Diez B. Roggisch

    #2
    Re: What does "*list&quo t; mean?

    Greg Smethells wrote:
    [color=blue]
    > 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:[/color]

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



    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

    Comment

    • Greg Brunet

      #3
      Re: What does "*list&quo t; mean?

      "Raymond Hettinger" <vze4rx4y@veriz on.net> wrote in message
      news:mfiWa.308$ W%3.168@nwrdny0 1.gnilink.net.. .[color=blue]
      > Hmm, it sounds like the *args calling format
      > needs to be added to the tutorial.
      >
      >
      > Raymond Hettinger[/color]

      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

      Comment

      Working...