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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

java - How to read a file created at runtime? -

php - Autoloader issue not returning Class -