
python
文章平均质量分 58
iteye_11140
这个作者很懒,什么都没留下…
展开
-
python dict输入顺序
最近在用python编程碰到这样的问题 >>> d={}>>> d['c'] = 1>>> d2: {'c': 1}>>> d['d']=2>>> d3: {'c': 1, 'd': 2}>>> d['b']=4&a2012-09-24 14:56:02 · 628 阅读 · 0 评论 -
tornado学习一
1 安装 从官网下载最新的tornado,(http://www.tornadoweb.org/) tar xvzf tornado-2.4.1.tar.gzcd tornado-2.4.1python setup.py buildsudo python setup.py install 2 tornado模块介绍 最重要的一个模块是w...原创 2013-01-24 10:58:08 · 120 阅读 · 0 评论 -
python的mysqldb封装类(转)
转自:http://blog.youkuaiyun.com/serverxp/article/details/6958459 #===============================================================================# -*- coding: utf-8 -*-#MySQLdb封装类#author:paul w...原创 2014-03-06 11:41:38 · 289 阅读 · 0 评论 -
python用mysqldb时查询缓冲问题
class DBBaseHandle: def __init__(self): try: self.conn = MySQLdb.connect(host=syn_config.mysql_server.get('host'), user=syn_config.mysql_server.get('user'), passwd=sy...原创 2014-03-06 11:31:25 · 1313 阅读 · 0 评论 -
centos升级python2.6到python2.7及相关库安装
下面列一下centos系统升级python到2.7以及安装相关库的步骤: 1 wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tgz2 tar xvf Python-2.7.5.tgz3 cd Python-2.7.54 ./configure 5 make all6 sudo make install7 ...2016-06-23 14:40:17 · 193 阅读 · 0 评论 -
mac 10.11安装lxml报错解决
由于接手新项目,项目里面需要安装lxml库通过最简单的安装:1 从网上下lxml的tar文件,2 pip install lxml安装开始了我痛苦的安装过程,在安装中报错:#include "libxml/xmlversion.h" ^ 1 error generated. error: command '/usr/bin/clang' failed with...2016-02-15 16:21:12 · 365 阅读 · 0 评论 -
递归遍历目录
下面是一个递归方法遍历目录,显示目录树的例子#encoding=utf-8import osimport sysdef main(path,depth=0): print depth * '|' + '|_',os.path.basename(path) if os.path.isdir(path): for item in os...2012-11-22 14:49:56 · 103 阅读 · 0 评论 -
python 安装库报gcc错
python 安装库报错:error: command 'gcc' failed with exit status 1解决办法:sudo apt-get install python-dev原创 2012-11-20 15:27:35 · 869 阅读 · 0 评论 -
python二分法查找
下面是一段用Python实现的二分法查找代码#encoding=utf-8import sysdef search2(a,m): low = 0 high = len(a) - 1 while low<=high: mid = (low + high)/2 midval = a[mid] ...2012-11-20 15:22:11 · 233 阅读 · 0 评论 -
简单的python发送接收邮件
利用python发送接收邮件: #encoding=utf-8import sysimport timeimport emailimport smtplibdef send_mail(): try: handle = smtplib.SMTP('smtp.126.com',25) handle.login('XXXX...2012-11-20 14:45:24 · 196 阅读 · 0 评论 -
python之yield学习
最近看新项目代码里有好多的yield,之前由于很少用,所以对其不慎了解,学习之。 yield就是一个生成器,也可以理解为自定义的迭代器,需要你每次调用next()或者是send()方法才能执行下去,直到碰到下一个yield。执行一个 send(msg) 会恢复 generator 的运行,然后发送的值将成为当前 yield 表达式的返回值。然后 send() 会返...原创 2012-11-01 14:00:33 · 84 阅读 · 0 评论 -
ubuntu python2.7安装mysql-python
Python连接mysql >>> import MySQLdbTraceback (most recent call last): File "<pyshell#2>", line 1, in <module> import MySQLdbImportError: No module named MySQLdb...原创 2012-10-31 17:07:31 · 401 阅读 · 0 评论 -
两个list合并成一个dict
已知 L1=['c','b','a'],L2=[1,2,3],将L1和L2合并成为L3={'a':1,'b':2,'c':3}样式解决方法:1 循环生成(这里不多说了)2 用dict和zip构造 >>> L1=['c','b','a']>>> L2=[1,2,3]>>> L3=dict(zip(L1[::-1]...2012-10-18 16:06:27 · 478 阅读 · 0 评论 -
tornado中finish和write区别
直接上代码:import tornado.ioloopimport tornado.webclass MainHandler(tornado.web.RequestHandler): def get(self): self.finish("haha") self.write("Hello, world")class TesH...2013-07-22 14:02:46 · 2866 阅读 · 0 评论 -
python 启动celery报错解决办法
今天由于接触新项目,安装一堆python库,而启动同步脚本时需要用到celery,下了最新的celery 3.0.11地址http://pypi.python.org/pypi/celery/安装启动报错:ValueError: Couldn't import 'celery.worker.strategy:default': 'latin-1' codec can't encode ...2012-09-29 11:09:23 · 1328 阅读 · 0 评论 -
python 字符串替换
python字符串替换有两种方法:1. replace>>> s = 'the table of contents for the book lists all of the modules covered'>>> s.replace('e','2')7: 'th2 tabl2 of cont2nts for th2 book lists ...2012-09-27 10:06:48 · 102 阅读 · 0 评论 -
使用Tornado+Nginx部署Django的一种尝试(转)
转自:奋斗足迹|崔玉松 http://fendou.org/post/2012/06/01/tornad-nginx-django/使用Tornado+Nginx部署Django的一种尝试Tornado是一个异步web框架和服务器,所以在开发longpulling的chat之类应用非常的合适,但是其实本身也是一个高性能的http服务器,也可以作为一个WSGIServer。所以即使你...原创 2013-04-22 16:01:49 · 272 阅读 · 0 评论