上一页 1 ··· 5 6 7 8 9
摘要: 1.combinations(iterable,r) 创建一个迭代器,返回iterable中所有长度为r的子序列,返回的子序列中的项按输入iterable中的顺序排序:官方文档def combinations(iterable, r): # combinations('ABCD', 2) --> AB AC AD BC BD CD # combinations(range(4), 3) --> 012 013 023 123 pool = tuple(iterable) n = len(pool) if r > n: return indice... 阅读全文
posted @ 2014-02-19 16:51 天外飞仙丶 阅读(11544) 评论(0) 推荐(0) 编辑
摘要: def f(n): while True: tmp = divmod(n, 2) if tmp[1]!=0: return False if tmp[0]==1: return True n = tmp[0] 阅读全文
posted @ 2014-02-18 16:44 天外飞仙丶 阅读(1229) 评论(0) 推荐(0) 编辑
摘要: 引自 python官方文档http://docs.python.org/2/library/functions.html range(stop) range(start,stop[,step])This is a versatile function to create lists containing arithmetic progressions. It is most often used inforloops. The arguments must be plain integers. If thestepargument is omitted, it defaults to1. .. 阅读全文
posted @ 2014-02-10 14:39 天外飞仙丶 阅读(713) 评论(0) 推荐(0) 编辑
摘要: Windows下 ,用PHP 实现文件上传 ,move_uploaded_file 将文件保存到指定路径时 ,报错failed to open stream ,经查找原来是编码问题 ,使用方法mb_convert_encoding 对文件进行转码 ,ubuntu环境下,没有此问题。1.mb_convert_encodingstring mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )str要编码的 string。to_encodingstr 要转换成的编码类型。from_e.. 阅读全文
posted @ 2014-01-06 13:48 天外飞仙丶 阅读(458) 评论(0) 推荐(0) 编辑
摘要: 在Python类的方法中,要调用父类中的某个方法可以这样写class A(object): def __init__(self): print 'A'class B(A): def __init__(self): print 'B' A.__init__(self)b = B()用类名来调用方法,这样一个类的父类发生变化时,子类也要修改,在复杂代码中就会很不方便,super()代码class A(object): def __init__(self): print 'A'class B(A): def __init... 阅读全文
posted @ 2013-11-27 15:42 天外飞仙丶 阅读(373) 评论(0) 推荐(0) 编辑
摘要: >>> a = -1>>> a &=0xffffffff>>> a4294967295L 阅读全文
posted @ 2013-11-26 14:14 天外飞仙丶 阅读(10055) 评论(0) 推荐(0) 编辑
摘要: 工作中需要用python程序使用AES对java程序经过AES加密的文件进行解密,解密后的文件与源文件对比发现后面多了一些字符,查找资料发现原来java在对文件进行加密时,对不是16的整数倍数时会对文件进行补位,而python在解密时没有将这些字符去掉。以下内容取自查找资料PyCrypto是流行... 阅读全文
posted @ 2013-11-26 14:03 天外飞仙丶 阅读(5199) 评论(0) 推荐(1) 编辑
摘要: ​​MongoDB启动时出现Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91 无法连接到mongoDB 可以通过指定dbpath 指定来解决,但这不是根本原因,MongoDB在非正常关闭时产生一个mongod.lock这样的.lock文件,只要将这个文件删除,然后重启mongodb服务即可, 在ubuntu下 mongo.lock文件在/var/lib/mongodb 这个目录下,重启命令 ​​/etc/init.d/mongodb restart 阅读全文
posted @ 2013-10-17 15:41 天外飞仙丶 阅读(977) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9