From 7387443a80caf2678db46067f4a37c6b38144c12 Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 16 Aug 2017 15:24:51 +0200 Subject: [PATCH] add getattr/setattr test --- attributes.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 attributes.py diff --git a/attributes.py b/attributes.py new file mode 100644 index 0000000..795db03 --- /dev/null +++ b/attributes.py @@ -0,0 +1,16 @@ +from __future__ import division, print_function + +class SomeClass(object): + def __setattr__(self, name, value): + print("Setting {} to value {}".format(name, value)) + self.__dict__[name] = value + + def __getattr__(self, name): + print("Getting {}".format(name)) + return None + +o = SomeClass() +o.xxx = "yyy" +o.xxx = "zzz" +print(o.xxx) # Note: __getattr__ does not get called here! +print(o.nope)