python3-cookbook

http://python3-cookbook.readthedocs.io/zh_CN/latest/index.html

一般的类找方法,通过MRO找到第一个就停了对吧,可以描述器好像会顺着MRO把所有的方法都执行一遍
原理????

rabbitmq
http://www.rabbitmq.com/tutorials/tutorial-one-go.html

python的xlutils 组件是不是不能处理xlsx格式 的excel?

有人用过python hdfs库或者pyhdfs库么,或者对hadoop熟悉

python 多继承详解

http://www.python.com/html/2013/pythonhexinbiancheng_0828/550.html
python装饰器 == 代码装B神器

class Descriptor:
def init(self, name):
self.name = name

def __get__(self, instance, cls):
    print('getting...')
    if instance is None:
        return self
    else:
        return instance.__dict__[self.name]

def __set__(self, instance, value):
    print("this is Descriptor.__set__")
    instance.__dict__[self.name] = value

def __delete__(self, instance):
    raise AttributeError("Can't delete")

class Typed(Descriptor):
ty = object
def set(self, instance, value):
print("this is Typed.__set__")
if not isinstance(value, self.ty):
raise TypeError('Expected {}'.format(self.ty))
super().__set__(instance, value)

class String(Typed):
ty = str

class PosFloat(Float, Positive):
pass
class Sized(Descriptor):
def init(self, *args, maxlen, **kwargs):
print("this is in Sized.__init__")
self.maxlen = maxlen
super().__init__(*args, **kwargs)

def __set__(self, instance, value):
    if len(value) > self.maxlen:
        raise ValueError('Too big')
    super().__set__(instance, value)

class SizedString(String, Sized):
pass
import re
class Regex(Descriptor):
def init(self, *args, pat, **kwargs):
print("this is in Regex.__init__")
self.pat = re.compile(pat)
super().__init__(*args, **kwargs)

def __set__(self, instance, value):
    if not self.pat.match(value):
        raise ValueError('Invalid string')
    super().__set__(instance, value)

class SizedRegexString(String, Sized, Regex):
pass

class Stock(Structure):
_fields = ['name', 'shares', 'price']
name = SizedRegexString('name', maxlen=8, pat='[A-Z]+$')
shares = PosInteger('share')
price = PosFloat('price')

s = Stock('XX', 50, 91.1)

__init__是可以通过__super__来实现,__set__和__get__是不是自带__super__功能啊

转载于:https://www.cnblogs.com/ITniu/p/5919755.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值