Calling methods in the same class
First of all, the method in the class needs to add the parameter self## when defining it. #, for example: (Recommended learning: Python video tutorial)
def SaveData(self,ip): print(ip)
The following is an example:
class A(): if __name__ == "__main__": print ('入口') self.Bfunc("192.168.1.1") def __init__(self): # 初始化;类似于C#中构造函数 def Afunc(self,ip): print(ip) def Bfunc(self,ip): self.Afunc(ip)
Call a method in another class
A.py and B.py are in the same folder ,can call each other through from file name import * or import A.
from A import A a = A() a.Afunc("123456") a.Bfunc("123456")
The above is the detailed content of How to call methods in a class in python. For more information, please follow other related articles on the PHP Chinese website!