A
A
Alexander Sadov2019-07-31 02:48:14
Python
Alexander Sadov, 2019-07-31 02:48:14

How to inherit self from parent class to child class which is inside it?

How to implement such a scheme, otherwise I can’t give an exact and intelligible answer

class Test:
   def __init__(self, name):
       self.name = name

   # Дочерний класс ( он находится в классе Test )
   class Other:
       def get_data(self):
          print(self.name) # Должен вывести ответ

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
snamef, 2019-07-31
@snamef

If you want to do this weird shit

class Test:
    def __init__(self, name):
        self.name = name
        self.other = self.Other(self)
        

    class Other:
        def __init__(self, test):
            self.test = test
        
        def get_data(self):

            print(self.test.name) 
          
          
a = Test('wohoo')

a.other.get_data()

but I wouldn't recommend it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question