Processing TypeError: testFunc () missing 1 required positional argument: 'self' - No error instantiating objects

In Python, a class in two steps:

  1. It should first be instantiated class;

  2. Then the application class. Note that the example of the process should be bracketed.

# - * - Coding: UTF-. 8 - * - 

'' 'in Python, should first instantiate a class, then the application class. Note that the example of the process should be bracketed. 
'' ' 
Class the TestClass: 
    DEF the __init __ (Self): 
        Print (' the In the init ') 
    DEF testFunc (Self): 
        Print (' the In testFunc ') 

' '' 
ERROR1: 
# wrong way: uninitialized 
print (TestClass.testFunc ( )) 
TypeError: testFunc (). 1 Missing required Positional argument: 'Self' 


ERROR2: 
# wrong way, TestClass: No parentheses 
testInstance the TestClass = 
Print (testInstance.testFunc ()) 
TypeError: testFunc (). 1 Missing required Positional argument: ' Self ' 
' '' 

# the right way, TestClass ():

In test testFunc
None

  

Guess you like

Origin www.cnblogs.com/Barrybl/p/12161922.html