Simple question on Parameters...

Fredrik Lundh fredrik at pythonware.com
Thu Dec 29 17:30:37 CET 2005


Hans Nowak wrote:

> You don't have to use fillColor[0], you can use tuple unpacking to name
> the elements of the tuple.  E.g.
>
> def renderABezierPath(self, path, closePath=True, outlineColor=(1.0,
> 1.0, 1.0, 1.0), fillColor=(0.0, 0.0, 0.0, 0.25)):
>      r, g, b, a = outlineColor
>      fr, fg, fb, fa = fillColor
>      ...do something with these values...

note that you can do the unpacking in the parameter list, if you
prefer:

>>> def render((r, g, b, a)=(1, 0, 0, 1)):
...     print r, g, b, a
...
>>> render()
1 0 0 1
>>> render((1, 1, 1, 0.5))
1 1 1 0.5

(but I'm not sure that combining unpacking and default values is
the best way to write readable code, though...)

</F>






More information about the Python-list mailing list