[ create a new paste ] login | about

Link: http://codepad.org/bXSWkPQO    [ raw code | output | fork ]

Python, pasted on Jan 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class OtherType(object):  # this is the one you didn't write
  # dummy implementations for the example:
  def set(self, D):
    print "setting", D
  def status(self, key):
    return "<value of %s>" % key

class Blah(object):
  def __init__(self, parent):
    object.__setattr__(self, "_parent", parent)

  def __getattr__(self, attr):
    return self._parent.status(attr)
  def __setattr__(self, attr, value):
    self._parent.set({attr: value})

obj = Blah(OtherType())
obj.velocity = 42
print obj.velocity


Output:
1
2
setting {'velocity': 42}
<value of velocity>


Create a new paste based on this one


Comments: