w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python: Call method by instance object: "missing 1 required positional argument: 'self'"

call_uselessmethod requires that there first be an instance of Class2 before you use it. However, by doing this:

k = Class2

you are not assigning k to an instance of Class2 but rather Class2 itself.

To create an instance of Class2, add () after the class name:

k = Class2()
k.call_uselessmethod()

Now, your code will work because k points to an instance of Class2 like it should.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.