Simple question on Parameters...

Will McGugan news at NOwillmcguganSPAM.com
Wed Dec 28 17:27:19 EST 2005


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")



More information about the Python-list mailing list