Re: Simple question on Parameters...
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 -- http://mail.python.org/mailman/listinfo/python-list
Simple question on Parameters...
I have defined a method as follows: def renderABezierPath(self, path, closePath=True, r=1.0, g=1.0, b=1.0, a=1.0, fr=0.0, fg=0.0, fb=0.0, fa=.25): Now wouldn't it be simpler if it was: def renderABezierPath(self, path, closePath=True, outlineColor, fillColor): But how do you set default vaules for outlineColor and fillColors? Like should these be simple lists or should they be structures or classes... -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question on Parameters...
On 28 Dec 2005 12:37:32 -0800, KraftDiner [EMAIL PROTECTED] wrote: I have defined a method as follows: def renderABezierPath(self, path, closePath=True, r=1.0, g=1.0, b=1.0, a=1.0, fr=0.0, fg=0.0, fb=0.0, fa=.25): Now wouldn't it be simpler if it was: def renderABezierPath(self, path, closePath=True, outlineColor, fillColor): But how do you set default vaules for outlineColor and fillColors? Like should these be simple lists or should they be structures or classes... def renderABezierPath(self, path, closePath=True, outlineColor=(1, 1, 1), fillColor=(0, 0, 0.25)): ... Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question on Parameters...
Il 2005-12-28, KraftDiner [EMAIL PROTECTED] ha scritto: I have defined a method as follows: def renderABezierPath(self, path, closePath=True, r=1.0, g=1.0, b=1.0, a=1.0, fr=0.0, fg=0.0, fb=0.0, fa=.25): Now wouldn't it be simpler if it was: def renderABezierPath(self, path, closePath=True, outlineColor, fillColor): But how do you set default vaules for outlineColor and fillColors? You can make renderABezierPath like this: def renderABezierPath(self, path, closePath=True, outlineColor=(1.0, 1.0, 1.0, 1.0), fillColor=(0.0, 0.0, 0.0, 0.25)): and in the body you unpack the tuples -- Lawrence - http://www.oluyede.org/blog Anyone can freely use whatever he wants but the light at the end of the tunnel for most of his problems is Python -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question on Parameters...
KraftDiner wrote: I have defined a method as follows: def renderABezierPath(self, path, closePath=True, r=1.0, g=1.0, b=1.0, a=1.0, fr=0.0, fg=0.0, fb=0.0, fa=.25): Now wouldn't it be simpler if it was: def renderABezierPath(self, path, closePath=True, outlineColor, fillColor): But how do you set default vaules for outlineColor and fillColors? Like should these be simple lists or should they be structures or classes... You could define a class for the r, g, b, a values, or just use tuples thusly.. def renderABezierPath(self, path, closePath=True, outlineColor=(1.0, 1.0, 1.0, 1.0), fillColor=(0.0, 0.0, 0.0, 0.25)): It all depends on what you find the most elegant solution. Im guessing you will use color values a lot, so I would recommend writing a simple class. Its also more natural to refer to the components of the color by name, rather than an index to the tuple. Will McGugan -- http://www.willmcgugan.com .join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in jvyy*jvyyzpthtna^pbz) -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question on Parameters...
I guess its all good... I just am not crazy about using fillColor[0] id rather use fillColor.r So is that a structure I need to define or a class... I'm kind of new to python what would that class or structure look like? and then do the default parameters still work? -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question on Parameters...
KraftDiner wrote: I guess its all good... I just am not crazy about using fillColor[0] id rather use fillColor.r 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... -- Hans Nowak http://zephyrfalcon.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question on Parameters...
NICE! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question on Parameters...
KraftDiner wrote: I guess its all good... I just am not crazy about using fillColor[0] id rather use fillColor.r So is that a structure I need to define or a class... I'm kind of new to python what would that class or structure look like? and then do the default parameters still work? There are no 'structures', as such in Python (not in the C sense). A color class could be defined like this.. class Color(object): def __init__(self, r, g, b, a): self.r= r self.g= g self.b= b self.a= a You can use instances of Color as a default parameter, but because defaults are evaluated once (at import time), it is usualy better to use None as the default, and act accordingly. eg. def renderABezierPath(self, path, closePath=True, outlineColor=None, fillColor=None): outlineColor = outlineColor or Color(1.0, 1.0, 1.0, 1.0) fillColor = fillColor or Color(0.0, 0.0, 0.0, 0.25) Will McGugan -- http://www.willmcgugan.com .join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in jvyy*jvyyzpthtna^pbz) -- http://mail.python.org/mailman/listinfo/python-list