首页 > 编程语言 > 详细

Python--私有

时间:2018-02-09 18:32:16      阅读:198      评论:0      收藏:0      [点我收藏+]
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()

Python--私有

原文:https://www.cnblogs.com/wangsilei/p/8436051.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!