Posted By

daeken on 07/27/06


python pyobjc objc

Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


PyObjC IVar Accessors

 / Published in: Python

Placing these inside a PyObjC class lets you access PyObjC instance variables starting with '_' without extra work while still allowing access to standard Python instance variables.

  1. def __getattr__(self, name):
  2. if name[0] == '_':
  3. return objc.getInstanceVariable(self, name)
  4. else:
  5. return self.__dict__[name]
  6. def __setattr__(self, name, value):
  7. if name[0] == '_':
  8. return objc.setInstanceVariable(self, name, value, 1)
  9. else:
  10. self.__dict__[name] = value
  11. return value

Report this snippet  

You need to login to post a comment.