class threading.Condition(lock=None) This class implements condition variable objects. A condition variable allows one or more threads to wait until they are notified by another thread. If the lock argument is given and not None, it must be a Lock or RLock object, and it is used as the underlying lock.
Otherwise, a new RLock object is created and used as the underlying lock.
也就是說,若是condition構造函數lock參數爲空的話,會自動建立可重入鎖RLock。python
可重入鎖RLock,同一線程能夠屢次獲取(the same thread may acquire it again without blocking)。閉包
在stackOverflow上看到的,python 2.5加了的if else實現相似三目運算符的功能:app
a if condition else b First condition is evaluated, then either a or b is returned based on the Boolean value of condition If condition evaluates to True a is returned, else b is returned.
甚至能夠這樣 : 1 if a > b else -1 if a < b else 0
ide
getattr、hasattr(它就是調用getattr,不拋出異常就返回True)setattr、delattr。函數
partial:ui
functools.partial(func[,*args][, **keywords]) Return a new partial object which when called will behave like func called with the positional arguments args and keyword arguments keywords. If more arguments are supplied to the call, they are appended to args. If additional keyword arguments are supplied, they extend and override keywords. Roughly equivalent to: def partial(func, *args, **keywords): def newfunc(*fargs, **fkeywords): newkeywords = keywords.copy() newkeywords.update(fkeywords) return func(*(args + fargs), **newkeywords) newfunc.func = func newfunc.args = args newfunc.keywords = keywords return newfunc
inspect.signature,能夠從一個可調用對象提取參數簽名信息。bind_partial()和bind()方法對提供的類型到參數名綁定,生成字典。lua
python lamda:spa
g = lambda x:x+1 g(1) >>>2 g(2) >>>3 lambda x:x+1(1) >>>2
__getattribute__方法,我嘗試在其中訪問self.name,出現了異常RuntimeError: maximum recursion depth exceeded while calling a Python object。遞歸深度超出。線程
def log_getattribute(cls): orig_getattribute = cls.__getattribute__ def new_getattribute(self, name): print 'getting:',name,self.name return orig_getattribute(self, name) cls.__getattribute__= new_getattribute return cls
難道這就是傳說中的閉包???code