随笔分类 -  python

摘要:pip 安装twisted库需要先安装依赖包,不然报"error: command 'gcc' failed with exit status 1" # yum install gcc python-devel# pip install twisted 阅读全文
posted @ 2016-07-05 00:07 weiokx 阅读(1383) 评论(0) 推荐(0)
摘要:方式一 使用yum安装 # yum install MySQL-python 方式二 使用pip 安装 # pip install mysql-python 使用pip方式安装需要提前安装如下依赖 mysql, mysql-devel, gcc libffi-devel python-devel o 阅读全文
posted @ 2016-07-04 20:10 weiokx 阅读(670) 评论(0) 推荐(0)
摘要:python logging 配置 在python中,logging由logger,handler,filter,formater四个部分组成,logger是提供我们记录日志的方法;handler是让我们选择日志的输出地方,如:控制台,文件,邮件发送等,一个logger添加多个handler;fil 阅读全文
posted @ 2016-06-16 23:09 weiokx 阅读(19438) 评论(0) 推荐(0)
摘要:python正则使用笔记 http://www.runoob.com/python/python-reg-expressions.html . 阅读全文
posted @ 2016-04-26 06:47 weiokx 阅读(165) 评论(0) 推荐(0)
摘要:写入excel, 保存的过程中需要注意,保存格式xls后缀,如果用xlsx会报错 读取excel . 阅读全文
posted @ 2016-04-08 19:41 weiokx 阅读(523) 评论(0) 推荐(0)
摘要:安装fabric $ pip install fabric 官网帮助文档:http://docs.fabfile.org/en/1.6/tutorial.html 阅读全文
posted @ 2016-04-07 19:02 weiokx 阅读(148) 评论(0) 推荐(0)
摘要:字符串在Python内部的表示是unicode 编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(encode)成另一种编码。 decode的作用是将其他编码的字符串转换成unicode编码,如str 阅读全文
posted @ 2016-03-30 02:41 weiokx 阅读(445) 评论(0) 推荐(0)
摘要:python中对文件、文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块。 得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 返回指定目录下的所有文件和目录名:os.listdir(path) 函数用来删除一个文件:os.remove(file) 删除多 阅读全文
posted @ 2016-03-30 00:28 weiokx 阅读(401) 评论(0) 推荐(0)
摘要:## test.py #########################import sysif __name__ == "__main__": args = sys.argv print args print len(args)######################$ python t... 阅读全文
posted @ 2015-12-12 11:06 weiokx 阅读(1338) 评论(0) 推荐(0)
摘要:import datetimeimport time#获取当前时间datetime.datetime.now()#获取当前日期datetime.date.today()#字符串转换为时间格式>>> t = time.strptime("2009-08-08", "%Y-%m-%d")>>> y,m,... 阅读全文
posted @ 2015-11-07 17:00 weiokx 阅读(419) 评论(0) 推荐(0)
摘要:内容链接:http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386832360548a6491f20c62d427287739fcfa5d5be1f000http://www.r... 阅读全文
posted @ 2015-11-07 15:59 weiokx 阅读(198) 评论(0) 推荐(0)
摘要:#coding=utf-8import urllib2import threadingimport timeTOTAL = 0 #总数 SUCC = 0 #响应成功数 FAIL = 0 #响应失败数 EXCEPT = 0 #响应异常数 MAXTIME=0 #最大响应时间 MINTIME=100 #最... 阅读全文
posted @ 2015-11-07 14:03 weiokx 阅读(6724) 评论(0) 推荐(0)
摘要:直接使用# pip install mysql-python 命令报 EnvironmentError: mysql_config not found 错误 安装mysql-phthon 需要用的mysql, mysql-devel, gcc libffi-devel python-devel op 阅读全文
posted @ 2015-10-28 11:37 weiokx 阅读(2382) 评论(0) 推荐(0)
摘要:以下是python脚本send_mms.py############################################from twisted.application import servicefrom twisted.internet import reactordef main(... 阅读全文
posted @ 2015-10-13 18:34 weiokx 阅读(344) 评论(0) 推荐(0)
摘要:今天来讨论一下装饰器。装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插入日志、性能测试、事务处理等。装饰器是解决这类问题的绝佳设计,有了装饰器,我们就可以抽离出大量函数中与函数功能本身无关的雷同代码并继续重用。概括的讲,装饰器的作用就是为已经存在的对象添加额外的功能。1. 装... 阅读全文
posted @ 2015-10-13 18:33 weiokx 阅读(355) 评论(0) 推荐(0)
摘要:{% for obj in ""|ljust:"10" %} {{ forloop.counter }} {% endfor %}官网是这样使用:ljustLeft-aligns the value in a field of a given width.Argument... 阅读全文
posted @ 2015-10-12 16:50 weiokx 阅读(291) 评论(0) 推荐(0)
摘要:你可以自定义一个MiddleWare类,然后在settings.py引用这个中间件,添加到MIDDLEWARE_CLASSES里,然后在公共模板里添显示代码即可。添加到公共模板里的代码:Python:%(pyTime).2fsDB:%(dbTime).2fsQueries:%(queries)d--... 阅读全文
posted @ 2015-10-12 16:48 weiokx 阅读(629) 评论(0) 推荐(0)
摘要:若不包含子目录的遍历:import globfor filename in glob.glob("/data/testdata/*.jpg"): print filename包含子目录import osimport fnmatchdef iterfindfiles(path, fnexp): f... 阅读全文
posted @ 2015-10-12 16:46 weiokx 阅读(1843) 评论(0) 推荐(0)
摘要:Python执行系统命令一般的用到了四种方法,第一种是 os.system(), 这个方法比较常用, 使用也简单, 会自动的生成一个进程,在进程完成后会自动退出, 需要注意的是os.system() 只返回命令执行的状态, 并不返回命令执行的结果,例如:>>> import os>>> s = os... 阅读全文
posted @ 2015-10-12 16:45 weiokx 阅读(1139) 评论(0) 推荐(0)
摘要:Python 运算符什么是运算符?本章节主要说明Python的运算符。举个简单的例子 4 +5 = 9 。 例子中,4和5被称为操作数,"+"号为运算符。Python语言支持以下类型的运算符:算术运算符比较(关系)运算符赋值运算符逻辑运算符位运算符成员运算符身份运算符运算符优先级接下来让我们一个个来... 阅读全文
posted @ 2015-09-17 09:32 weiokx 阅读(345) 评论(0) 推荐(0)