03 2012 档案
摘要:L1 cache reference0.5 nsBranch mispredict5 nsL2 cache reference7 nsMutex lock/unlock100 nsMain memory reference100 nsCompress 1K bytes with Zippy10,000 nsSend 2K bytes over 1 Gbps network20,000 nsRead 1 MB sequentially from memory250,000 nsRound trip within same datacenter500,000 nsDisk seek10,000,0
阅读全文
摘要:1. propertyclass C(): def SetIt(self): self.a = 1 def GetIt(self): return self.a content = property(SetIt, GetIt)c = C()c.content = 1print c.content # will print 12. idid(1) # this is a number..3. weakrefimport weakrefclass C(): def func(self): passc = C()c.func()p =...
阅读全文
摘要:Decorate是装饰的意思。如果你了解Decorator设计模式,那么就很好理解Python的Decorator。http://en.wikipedia.org/wiki/Python_syntax_and_semantics#DecoratorsDecorator是一个可调用的python object。Decorator可以用来修改funciton, method 或者类的定义。一个object被传进decotator,然后decorator修改这个object并且返回这个object,最后,这个返回的object绑定到原来的那个object的名字上。Decorator是一个语法糖(sy
阅读全文
摘要:with 关键字的意思就是一种try finally的快捷写法看下面的代码和注释就容易理解with WithWrapper() as ww: print ww # 应该打印 1. 它是WithWrapper().__enter__函数的返回值 print "with body" raise NameError("Error Raised") # 这里如果有异常, WithWrapper().__exit__函数的后三个参数就根据这个异常被赋值。否则三个参数的值都是Noneclass WithWrapper: def __enter__(self): pr
阅读全文
浙公网安备 33010602011771号