<- Back | Index | Forward ->

Object Attributes

We use this to make toolkit function calls look like attributes:
  class Atom:
      def __init__(self, handle):
          self.handle = handle

      def __getattr__(self, name):
          if name == "charge":
              return dt_charge(self.handle)
          raise AttributeError, name

      def __setattr__(self, name, val):
          if name == "charge":
              return dt_setcharge(self.handle, val)
          self.__dict__[name] = val
  
  
  a = Atom(12)
  print a.charge
  a.charge = 2