On Sep 6, 10:55 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Sep 6, 6:26 pm, rh0dium <[EMAIL PROTECTED]> wrote: > > > Hi all, > > > I have the following piece of code and I wanted to set the default > > attributes based on a dictionary. What I am looking for is a way to > > take PIPODEFAULTS and assign each one as an attribute for the class > > pipo. Can someone show me how to do this by iterating over the > > PIPODEFAULTS and assign them. What I would expect to be able to do is > > call the class and modify them. > > Use the setattr(...) function. > > > > > example: > > a = pipo() > > print a.caseSensitivity > > "preserve" > > > a.caseSensitivity = "lower" > > print a.caseSensitivity > > "lower" > > > Lastly - here is my code: > > > class pipo: > > > PIPODEFAULTS={ "caseSensitivity" : "preserve","cellMapTable" : > > "","checkPolygon" : "nil","compression" : "none", > > "convertDot" : "ignore","convertPathToPoly" : > > "nil","convertToGeo" : "nil","dumpPcellInfo" : "nil", > > "snapToGrid" : "nil","techFileChoice" : > > "nil","units": "micron","useParentXYforText" : "nil","viewName" : > > "layout", > > } > > > def __init__(self, *args, **kwargs): > > """This simply will run a PIPO stream out > > """ > > # Setup Logging > > self.pipoargs=self.setdefaults() > > def setdefaults(self): > > for x in self.PIPODEFAULTS: > > self.log.debug("Setting %s to %s" % (x, > > self.PIPODEFAULTS[x])) > > def setdefaults(self): > for key, val in self.PIPODEFAULTS.iteritems(): > setattr(self, key, val) >
Hey this is great!!! Simple and clear. I appreciate it!! -- http://mail.python.org/mailman/listinfo/python-list