码迷,mamicode.com
首页 > 编程语言 > 详细

Python--私有

时间:2018-02-09 20:46:26      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:turn   print   python   ati   init   static   password   div   类方法   

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--私有

标签:turn   print   python   ati   init   static   password   div   类方法   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!