Drickken Drickken - 1 year ago 26
Python Question

How to access functions that use self outside of class

I have been trying to access a function made within a class outside of said class.
If self is not one of the function's parameters it works just fine, as in:

class Dog():

def Bark():

Marley = Dog


But If I add self to Bark() as in:

class Dog():

def Bark(self):

def Bark_lots(self):
for I in range(3):

Marley = Dog


Then python throws a type error:

TypeError: Bark_lots() missing 1 required positional argument: 'self'

Everything that I've searched up just talks about why self is needed and what it does. I am clearly missing something, and from past experience it is probably simple. Any help on this issue would be much appreciated.

(Also I am new to stack exchange/ stack overflow, If I broke any of the rules please alert me to where and I will fix it.)


After the call сlass you need to put parenthesis (Dog(), not Dog):

Marley = Dog()