2013/7/4 Chris Withers <ch...@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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com