2013/7/4 Chris Withers <chris at simplistix.co.uk>: > That doesn't seem helpful as a sensible way to get back to the class object: > >>> globals()[MyClass.method.__qualname__.split('.')[0]] > <class '__main__.MyClass'> globals() can only be used if MyClass is in the same module. Otherwise, you a more complex function: --------------- import types def get_function_class(func): obj = func for name in func.__qualname__.split('.')[:-1]: if name == "<locals>": raise ValueError("you lose") if isinstance(obj, types.FunctionType): obj = func.__globals__[name] else: # get a method of a class, or a class defined in a child obj = getattr(obj, name) return obj --------------- Victor
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4