let say i have
class Blah:
def __init__(self):
self.foo = ...
self.bar = ...
foo and bar does NOT implement getattr. And they dont have attr "abc" and "xyz"
Is it possible to trick it to do
b = Blah()
x = b.foo.abc
y = b.bar.xyz
OR
x = b.abc.foo
y = b.xyz.bar
foo and bar may not even exists i.e. sort of virtual
No, it's not possible. When you do
it's essentially equivalent to
When you're using
.abc, there's no reference to theBlahinstance any more, you're just getting it from whatever value was stored in thefooattribute. So if that value doesn't have anabcattribute or__getattr__method, you'll get an error.There's no way for
Blahto intercept the access to the next level below its attributes.