e44d26ae0c
It's not completely satisfactory, because a failed call to __getattr__ should not raise an exception. __setattr__ could be implemented, but it would slow down all stores to a user created object. Need to implement some caching system.
12 lines
176 B
Python
12 lines
176 B
Python
# test __getattr__
|
|
|
|
class A:
|
|
def __init__(self, d):
|
|
self.d = d
|
|
|
|
def __getattr__(self, attr):
|
|
return self.d[attr]
|
|
|
|
a = A({'a':1, 'b':2})
|
|
print(a.a, a.b)
|