Help setting default class attributes

rh0dium steven.klass at gmail.com
Thu Sep 6 13:26:34 EDT 2007


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.

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




More information about the Python-list mailing list