zoukankan      html  css  js  c++  java
  • 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__功能啊

  • 相关阅读:
    JVM OOM处理
    Scala可变参数列表,命名参数和参数缺省
    Scala闭包
    Scala应用函数
    Scala函数字面量简化写法
    Scala函数字面量
    Scala中class和object的区别
    数据库的优化
    svn: warning: 'xxxxxx' is already under version control
    svn status 显示 ~xx
  • 原文地址:https://www.cnblogs.com/ITniu/p/5919755.html
Copyright © 2011-2022 走看看