Assigning 'nochage' to a variable.

Diez B. Roggisch deets at nospam.web.de
Sun Sep 4 22:58:15 CEST 2005


cjfrovik at gmail.com wrote:
> Has anyone else felt a desire for a 'nochange' value
> resembling the 'Z'-state of a electronic tri-state output?

No. but if you must, you can emulate that using properties or 
__getattr__/__setattr__- of course then limited to classes, but writen 
c.var1 instead of var1 where c is your container - that world work, if 
the semantics you need are so commeon it really saves you effort.

class Container(object):

     def __init__(self, nc):
         """
         @param nc: a list or set of names that should not be
         overwritten when None is assigned to them.
         """
         self.nochanges = nc

     def __setattr__(self, name, value):
         if name in self.nochanges and value is not None:
            self.__dict__[name] = value

Diez



More information about the Python-list mailing list