摘要:https://www.quora.com/Whats-the-difference-between-iterators-and-generators-in-Python
阅读全文
摘要:As Python updating to python 3.6, its performance is better than Python 2.x, which is good news to every Python developer. I would like to write down
阅读全文
摘要:After running celery in my machine, I got this: Solution 1: Solution 2:
阅读全文
摘要:不同函数调用方式对应不同的绑定次数:import profileclass A: def f(self): passdef foo(): a = A() for i in range(100000): a.f()if __name__ == '__mai...
阅读全文
摘要:一、Python和C扩展cPython是C编写的,python的扩展可以用C来写,也便于移植到C++.编写的Python扩展,需要编译成一个.so的共享库。Python程序中。官方文档:https://docs.python.org/2/extending/extending.html#writin...
阅读全文
摘要:看到一Python例子,挺有意思的,用Python模拟C++的输出流OStream.单纯只是玩。原理: 利用Python __lshift__左移内建函数<<,调用时将输出内容,如果内容为回车,则处理回车。看例子^_^!!!#coding: utf-8class IOManipulator(obje...
阅读全文
摘要:迭代dict也要讲求效率,不然就要走进性能陷阱以下三种迭代方式:keys,iterkeys, hashkeyimport timeitDICT_SIZE = 100 * 100000testDict = dict()for i in xrange(DICT_SIZE): testDict[i]...
阅读全文
摘要:一、property解释 根据文档资料解释:property([fget[, fset[, fdel[, doc]]]])Return a property attribute for new-style classes (classes that derive from object) 使用这...
阅读全文
摘要:问题:假设有500w条数据,数据是在2^32-1的范围内,数据重复,如何减少内存对数字进行统计呢? 如果用字典来标记数字是否已经统计过来,数字做为key, value仅为0 or1,那么这样需要消耗内存32*500w+32*500w,key和value占用内存相加。 但如果我们用value的位来...
阅读全文
摘要:最近发现一服务器一个奇怪的现象: Django的视图函数在浏览器一个请求的情况下,竟然做了两个请求的函数处理。不可思议,找了几天也不知道为什么,只发现只要用uwsgi_read_timeout之后,如果请求时间超时,Nginx acess log便会记两条同样的log。uwsgi_read_tim...
阅读全文
摘要:#!/usr/bin/env python#-*- coding:utf-8 -*-import timestart = time.time()for i in range(1000000): a = (1, 2, 3, 4)print time.time() - startstart = t...
阅读全文
摘要:Python字典dictDict的创建有以下几种:dict1 = {}dict2 = {'x': 1, 'y': 2}dict1 = {}.fromkeys(('x', 'y'), 1)dict2 = {}.fromkeys(('x', 'y'))dict1 = dict((['x', 1], ['...
阅读全文
摘要:今天学习Django,再创建生成Model后,在管理界面点击add添加中文数据,出现如下问题:Exception Type:UnicodeEncodeErrorException Value:'ascii' codec can't encode characters in position 4-7:...
阅读全文