10 2011 档案
摘要:python中with可以明显改进代码友好度,比如:with open('a.txt') as f: print f.readlines() 为了我们自己的类也可以使用with, 只要给这个类增加两个函数__enter__, __exit__即可:>>> class A: def __enter__(self): print 'in enter' def __exit__(self, e_t, e_v, t_b): print 'in exit' >>> with A() as a: print 'in
阅读全文
摘要:比如现在有html(django template)如下:<li class="jstree-closed"> <ins class="jstree-icon"> </ins> <a href="#" name="template_category_item" value="{{key}}"><ins class="jstree-icon"> </ins>{{key}}</a> <ul&
阅读全文
摘要:一直对itertools怀有敬畏之心,其实会了就还好了,that's nothing这里的迭代器最主要得特点就是lazy,和stl里面得迭代器还是不一样得,最明显得好处就是节省内存了。顾名思义,itertools得函数返回得都是迭代器,为简单起事,下面就不专门说明了count(p,q) 返回p, p+q, p+2*q, ....cycle(p) 返回 p[0], p[1],...p[last],p[0],p[1]......repeat(p, n) 返回 p...p (n times)chain(p,q..) 把几个参数连接起来compress(data, selectors) 比如c
阅读全文
摘要:In [6]: def return_non(): print '-----------' ...: while True: ...: print '##############' ...: x = yield ...: print x ...: print '%%%%%%%%%%%%' ...: In [8]: y = return_non() In [9]: y Out[9]: <generator object return_non at ...
阅读全文
摘要:echo "deb http://archive.canonical.com/ubuntu maverick partner" >> /etc/apt/sources.listapt-get updateapt-get install sun-java6-jdk sun-java6-jre an subversion设置好JAVA_HOME下载red5, 我下载了red5-1.0.0-RC1.tar.gztar xvfz red5-1.0.0-RC1.tar.gzmv red5-1.0.0 /usr/share/red5cd /usr/share/red5exp
阅读全文
摘要:看django文档看到关于models.manager时候,前面custom manager都还好懂,但这个use_for_related_fields一时没看懂,搜了下,下面这个在stackoverflow上的回答很好,记一下http://stackoverflow.com/questions/6067195/how-does-use-for-related-fields-work-in-django简单来说, use_for_related_fields作用就是当另一个model实例通过字段引用该model时,使用该model指定的manager而不是使用django.db.models.
阅读全文

浙公网安备 33010602011771号