python
iteye_3128
这个作者很懒,什么都没留下…
展开
-
python **args * args
转载 http://jimi68.iteye.com/blog/200514 先来看个例子: Pthon代码 def foo(*args, **kwargs): print 'args = ', args print 'kwargs = ', kwargs print '------------------------------...原创 2012-03-06 10:28:20 · 87 阅读 · 0 评论 -
python 使用ConfigParser,ConfigObj读取配置
使用python 从配置文件获取配置: import ConfigParser config = ConfigParser.ConfigParser() #@staticmethod def getValue(keyName): with open('./conf/system.properties', 'r') as cfg: conf...原创 2013-09-25 16:14:09 · 499 阅读 · 0 评论 -
python tarfile-打包解包
最近项目上有一个ftp上传程序,需要把碎文件打包上传,到服务端再解包。本来已经只能通过shell来搞这个了,无奈打包过程中有一部分业务逻辑,不能把整个目录都打包,惊喜地发现python有tarfile这个东西,太惊喜了,试用完后发现还挺不错,打包一组466M的文件,共778个文件花了1.9s,解包花了2.3s。打包,解包代码如下: tar打包 在写打包代码的过程中,使用tar.add...原创 2013-09-12 17:20:15 · 636 阅读 · 0 评论 -
python 从另一个包导入文件
文件目录 _ |_utils_ | |_utils.py |_xk.py 想要从xk.py import utils.py里面的函数 需要在utils里面加入__init__.py使utils不仅仅是一个文件夹,而是一个模块 如果xk.py在另一个模块里,而不是在根目录下 需要在xk.py首部加上 import sys ...原创 2012-04-06 14:43:07 · 403 阅读 · 0 评论 -
python,with open
用python的时候,会经常遇到文件数据库的open,但总会不小心忘了close 用with open 语句就能很好的解决这个问题,它会在语句执行完后,自动执行close() with open('./prepare_channels.txt', 'r') as f: for s in f: channels.add(s.strip())...原创 2012-04-06 10:18:19 · 526 阅读 · 0 评论 -
python 如何在一个文件中调用另一个文件的类
#filename xk class class AClass: def __init__(self,name): print name a=AClass("sadfaf") 开始尝试的是用 import xk a=AClass("sadfaf") 执行出错 原因 一直以为python和Java是一样的,类名要和...原创 2012-04-05 11:58:23 · 1026 阅读 · 0 评论 -
python产生随机数
这些方法位于random模块中 random.random(),同javascript的Math.random(),返回[0.0,1)之间的浮点数 random.uniform(a, b),返回[a,b]之间的浮点数 print random.uniform(10, 20) print random.uniform(20, 10) #---- 结果(不同机器上...原创 2012-03-15 17:47:29 · 365 阅读 · 0 评论 -
python time,datetime,string转换
#把datetime转成字符串 def datetime_toString(dt): return dt.strftime("%Y-%m-%d-%H") #把字符串转成datetime def string_toDatetime(string): return datetime.strptime(string, "%Y-%m-%d-%H") #把字符串转成...原创 2012-03-13 11:04:32 · 837 阅读 · 0 评论 -
优化从mongdb取数据python代码,用于出fusioncharts图
原始代码 def ioBandwidth(request): beginDate = request.GET.get("beginDate") collection = getCollection() data = collection.find().sort("InsertDate",pymongo.ASCENDING) mscombi2d.cat...原创 2012-03-09 14:02:48 · 99 阅读 · 0 评论 -
Python搭配MongoDB使用方法
Python搭配MongoDB使用方法 原文地址:http://serholiu.com/python-mongodb 下面就谈谈Python操作MongoDB的一些基本用法,先介绍一下MongoDB,这是现在风头正劲的NoSQL数据库,没有关系数据库那种表之类的概念,就像Python中的字典一样,一个键对应一个值,然后这些键值组成一个文档,然后文档组成一个集...原创 2012-03-09 10:00:41 · 176 阅读 · 0 评论 -
Python日期和字符串的互转
原文地址:http://hi.baidu.com/qinghua9/blog/item/cf9fafccd71e661900e92870.html 用的分别是time和datetime函数 import time,datetime # date to strprint time.strftime("%Y-%m-%d %X", time.localtime()) #str t...原创 2012-03-09 09:55:02 · 166 阅读 · 0 评论 -
flask-sqlachemy note
between datetime按天查询 Myclass.query.filter(myClass.date.between(_date, _date+timedelta(days = 1))) filter 和 filter_by的区别 session.query(MyClass).filter(MyClass.name == 'some name') session...原创 2012-12-10 17:15:10 · 123 阅读 · 0 评论