D
D
DecafNickel2020-01-04 23:33:07
Python
DecafNickel, 2020-01-04 23:33:07

How to properly use inheritance in python3?

I have two classes, and one is the parent and the second is the child. When I try to call the parent method, I get an error that the Self argument is missing.
Code example:

class Osnovnoy:
def __init__(self):
self.data = '1100111001010'
def method(self):
return f'{self.data}printuem'
class Rebyonok(Osnovnoy):
def method(self):
print(Osnovnoy.method( ))

Add. child class example:
class Eto(Master):
def __init__(self):
super().__init__()
def baloonl():
vari = ['Yes', 'No']
ans = random.choice(vari)
requests.post(Master.sendMessage (), data = 'tut something bilo')

Additional example of a parent class:
class Master:
def __init__(self):
self.link = 'data1'
self.data2 = 'data2'
def sendMessage(self):
send = f'{self.link}/sendMessage'
return send

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DecafNickel, 2020-01-05
@DecafNickel

In general, as comrade Nikita Panyukhin noted, I forgot the brackets ...
here is a more correct code example:

class Master:
    def __init__(self):
        self.link = '0101010'
        self.data2 = None
    def sendMessage(self):
        var = f'{link}/printuem'
        return var

class Slave(Master):
     
    def met(self):
            vari = ['Yes', 'No']
            ans = random.choice(vari)
            requests.post(self.sendMessage(), data = ans)

sl = Slave
st.met()

the line " sl = Slave " should be replaced with " sl = Slave() "

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question