python 绑定方法,非绑定方法
import test
class A():
def __init__(self, ip, port):
self.ip = ip
self.port = port
@classmethod
def from_conf(cls):
return cls(test.ip, test.port)
obj = A.from_conf()
print(obj.__dict__)
class A():
def __init__(self,ip,port,name):
self.name = name
self.ip=ip
self.port=port
@classmethod
def from_conf(cls,*args):
return cls(test.ip, test.port,*args)
@staticmethod
def f1():
print('i am staticmethod')
def f2(self):
print(f'{self.name}')
obj=A.from_conf('eric')
print(obj.from_conf)
print(obj.f1)
print(obj.f2)
print(obj.__dict__)