python how to make inner class to be type of outer class -


i have nested classes because tightly related.

now want have following type of code

class one(some-other-type):     ...     // more functions here      class two(one):        // more functions here. 

the inner class "two" type should "one" if put error. other way not make nested below

class one(some-other-type):     ...     // more functions here  class two(one):     // more functions here. 

but dont want class "two" accessible when module imported. dont care functions offered "one" needs under clarity of code.

any thoughts?

you cannot refer class while being constructed. can refer class inside own method since method body isn't evaluated until after class in constructed.

class one(object):     @staticmethod     def get_two():         class two(one):            pass         return two()     def f(self):         print("i %s" % type(self).__name__) 

two inherits f one

>>> obj = one.get_two() >>> obj.f() "i two" 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -