import redis class MyRedis(object): xiaohei = 'hahaha' def __init__(self, host, password='', port=6379): self.__host = host self.password = password self.port = port self.__coon_redis() def __coon_redis(self): self.coon = redis.Redis(host=self.__host, password=self.password, port=self.port) def get(self, k): print(self.__host) return self.coon.get(k).decode() @staticmethod # 静态方法 def other(): print('我是other!') @classmethod # 类方法 def class_func(cls): print(cls.xiaohei) cls.class_func1() @classmethod def class_func1(cls): print('我是类方法1') # r = MyRedis('211.149.218.16', '123456') MyRedis.other() MyRedis.class_func()