diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-31 22:57:56 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-31 22:57:56 +0100 |
commit | e44d26ae0c1b5d248fa4db112cdeabe404944f3c (patch) | |
tree | 03bad17caf73555d5880263e894b5dc2fdb5dbe2 /tests/basics/getattr.py | |
parent | 4db727afea0082780fca558ff251afb4a8b32ad7 (diff) | |
download | micropython-e44d26ae0c1b5d248fa4db112cdeabe404944f3c.tar.gz micropython-e44d26ae0c1b5d248fa4db112cdeabe404944f3c.zip |
py: Implement __getattr__.
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.
Diffstat (limited to 'tests/basics/getattr.py')
-rw-r--r-- | tests/basics/getattr.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/basics/getattr.py b/tests/basics/getattr.py new file mode 100644 index 0000000000..a021e38fb0 --- /dev/null +++ b/tests/basics/getattr.py @@ -0,0 +1,11 @@ +# 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) |