Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > What does "*list" mean?

Reply
Thread Tools

What does "*list" mean?

 
 
Greg Smethells
Guest
Posts: n/a
 
      07-31-2003
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
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      07-31-2003
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
 
Reply With Quote
 
 
 
 
Greg Brunet
Guest
Posts: n/a
 
      08-01-2003
"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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET 2.0 ASPx Page does not load, but HTM does prabhupr@hotmail.com ASP .Net 1 02-08-2006 12:57 PM
Button OnClick does not fire on first postback, but does on second Janet Collins ASP .Net 0 01-13-2006 10:08 PM
Does the 2.0 Framework come out when Visual Studio .NET 2005 does? needin4mation@gmail.com ASP .Net 3 10-07-2005 12:55 AM
CS0234 Global does not exist ... but it genuinely does Bill Johnson ASP .Net 0 07-08-2005 06:34 PM
Does no one else think microsoft does a poor job? =?Utf-8?B?SmVyZW15IEx1bmRncmVu?= Wireless Networking 2 11-20-2004 12:17 AM



Advertisments