diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-11 19:05:42 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-11 20:51:30 +0300 |
commit | ff30666c69161e30ec5c44446b60042eb932619a (patch) | |
tree | 2452971faff9695fe9b36eee22e5ade1cb4a7bce /tests/basics | |
parent | a0863158f5a3dc13dde565b9eada8542df17a7a8 (diff) | |
download | micropython-ff30666c69161e30ec5c44446b60042eb932619a.tar.gz micropython-ff30666c69161e30ec5c44446b60042eb932619a.zip |
py: Add basic implementation of hasattr() function.
Diffstat (limited to 'tests/basics')
-rw-r--r-- | tests/basics/hasattr1.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/basics/hasattr1.py b/tests/basics/hasattr1.py new file mode 100644 index 0000000000..b1c4b5ceb6 --- /dev/null +++ b/tests/basics/hasattr1.py @@ -0,0 +1,29 @@ +class A: + + var = 132 + + def __init__(self): + self.var2 = 34 + + def meth(self, i): + return 42 + i + + +a = A() +print(hasattr(a, "var")) +print(hasattr(a, "var2")) +print(hasattr(a, "meth")) +print(hasattr(a, "_none_such")) +print(hasattr(list, "foo")) + +class C: + + def __getattr__(self, attr): + if attr == "exists": + return attr + raise AttributeError + +c = C() +print(hasattr(c, "exists")) +# TODO +#print(hasattr(c, "doesnt_exist")) |