python version 3.5.2
I tried to get parent class from a child class:
class A:
pass
class B(A):
pass
after a little research, I got a solution from python doc: use __base__
. (a special class attribute)
But I couldn't find this "__base__"
in B.__dict__
or dir(B)
, which are my normal ways of getting attributes.
This is definitely class related information, if it's not in B.__dict__
where is it? (although I realized that "__base__"
is returned by type(B).__dict__
)
And why isn't dir()
returning it? based on this stackoverflow question I read, dir()
has some logics behind and it is supposed to return "a complete picture of all available attributes."
I initally thought this is hiding on purpose...but you can still easily manipulate a child's parent:
class C:
pass
B.__bases__ = (C,) # voila, B got a new Dad