python: determine if a class is nested
问题 Suppose you have a python method that gets a type as parameter; is it possible to determine if the given type is a nested class? E.g. in this example: def show_type_info(t): print t.__name__ # print outer class name (if any) ... class SomeClass: pass class OuterClass: class InnerClass: pass show_type_info(SomeClass) show_type_info(OuterClass.InnerClass) I would like the call to show_type_info(OuterClass.InnerClass) to show also that InnerClass is defined inside OuterClass. 回答1: AFAIK, given a