Xiayf的技术笔记

Python

基础知识

对于元组、列表、字符串等类型的变量,在其上面加上星号(*)然后传递,其效果是将该变量数据进行unpack(解包)后在传递。

扩展阅读知乎:元组的reference前加个星号是什么意思?

根据字符串获取某对象以该字符串命名的属性/方法:

def getattr(object, name, default=None): # known special case of getattr
    """
    getattr(object, name[, default]) -> value

    Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.
    When a default argument is given, it is returned when the attribute doesn't
    exist; without it, an exception is raised in that case.
    """

根据字符串查询某对象是否有以该字符串命名的属性/方法:

def hasattr(p_object, name): # real signature unknown; restored from __doc__
    """
    hasattr(object, name) -> bool

    Return whether the object has an attribute with the given name.
    (This is done by calling getattr(object, name) and catching exceptions.)
    """

反射

Python自省(反射)指南

stackoverflow - Python: Once and for all. What does the Star operator mean in Python?

魔术方法

A Guide to Python's Magic Methods

Python魔术方法指南

装饰器

Python装饰器入门

装饰器与函数式Python

值得关注

Event driven framework for Python

推荐阅读