HC Library and *attributes parameter
Steve Holden
steve at holdenweb.com
Fri Mar 11 06:02:43 EST 2005
Efrat Regev wrote:
> Hello,
>
> I'm a really new (and quite bad) Python programmer. While trying to use
> the HC HTML-Generating library, I couldn't figure out how to set a table's
> width to some given width. Moreover, the constructors interface is
>
> def __init__(self, object = None, align = None, border = None, cellspacing =
> None, cellpaddding = None, *attributes)
>
> So, what does *attribute stand for (being a C++ programmer, it looks
> like a pointer, probably not the case). Is it like the C++ ellipsis? If so,
> how can
> I use it?
>
The notation "*attribute" in the function signature denotes a variable
number of positional arguments, which are provided to the function body
as a tuple named attribute.
>>> def f1(a, b, *c):
... print "a:", a
... print "b:", b
... print "c:", c
...
>>> f1(1, 2, 3, 4, 5)
a: 1
b: 2
c: (3, 4, 5)
>>> f1('one', 'two')
a: one
b: two
c: ()
>>>
Much easier than varargs in C!
The notation **kw similarly denotes a variable number of keyword
arguments, which are provided to the function body as a dictionary named kw.
regards
Steve
More information about the Python-list
mailing list