__init__ # 只要类名后面加(), 就会自动执行该类的__init__方法
如下:
class SQLHelper: h_host = ‘cl.salt.com2‘ u_username = ‘alex2‘ u_password = ‘1234‘ def __init__(self): print(‘自动执行__init__方法‘) def fetch(self, sql): print(self.h_host) print(self.u_username) print(self.u_password) print(sql) def create(self, sql): pass def remove(self, nid): pass def modify(self, name): pass obj = SQLHelper()
时间: 2024-12-28 16:32:41