I have some namespaces, one included in the other:
class A:
class B:
class C:
def method(): pass
get_ns_path(A.B.C.method) # >>> 'A.B.C.method'
Is it possible to implement such get_ns_path(func) that receives a method/function and returns the 'namespace path' as a string?
A.B.C.method.im_class gives C, great, but how to go further up?
I don't think that is possible:
>>> dir(A.B.C)
['__doc__', '__module__', 'method']
More convincingly, there's no reason A.B.C should know about A.B, because you can do Z.C = A.B.C and they would be the same object. So what would get_ns_path(Z.C.method) return?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With