![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
tudou_zp
这个作者很懒,什么都没留下…
展开
-
fileinput: inplace
<br />if inplace is set as 1, then print will flush back the output to input file<br /> <br />def file_insert( fname, linenos = [], strings = [] ):<br /> <br />lineno = 0 # record the line no in the file <br />i = 0 # record the no. in linenos<br /> <br /原创 2011-02-15 15:56:00 · 498 阅读 · 0 评论 -
时间和时间戳互换
<br />当前时间戳:time.time()<br />当前日期:time.ctime()<br />1、Python下日期到时间戳的转换<br />import datetime<br />import time<br />dateC=datetime.datetime(2010,6,6,8,14,59)<br />timestamp=time.mktime(dateC.timetuple())<br />print timestamp<br />2、Python下将时间戳转换到日期<br />impo原创 2011-02-15 11:48:00 · 734 阅读 · 2 评论 -
正则表达式- 捕获组 非捕获组
<br />捕获组:<br />就是把正则表达式中子表达式匹配的内容,保存到内存中以数字编号或显式命名的组里,方便后面引用。当然,这种引用既可以是在正则表达式内部,也可以是在正则表达式外部。<br /><br />temp record:<br />http://blog.sina.com.cn/s/blog_4dbe98f10100djnj.html<br />http://blogold.chinaunix.net/u/16928/showart_2504838.html<br />http://hi.原创 2011-02-14 18:55:00 · 911 阅读 · 2 评论 -
python 执行命令 获取返回值 和 print内容 用module commands
<br />如果想获取执行命令的状态值,也就是$?, 可以用os.system( cmd )<br />如果想获取执行命令的print内容, 可以用os.popen( cmd ).read()<br /> <br />如果既想获取状态值,也想获取打印的内容?。。。。<br />import commands<br /> <br />stat, content = commands.getstatusoutput( cmd )<br />stat is the exit code<br />content i原创 2011-02-17 16:00:00 · 2994 阅读 · 2 评论 -
Small tricks
不想让转义生效: print r'/t/r‘à /t/runicode()函数可将字符串转为unicode字符串, 要使用Unicode字符串,只要在字符串前加上“u”即可 支持中文:encoding=utf-8或gbk或gb2312# -*- coding: utf-8 -*-array.array:typecode:c => charb(B) => byte(unsigned byte)h(H) => short(unsigned short)i(I) => init( unsigned原创 2011-02-16 17:07:00 · 378 阅读 · 0 评论 -
python bisect module
<br />import bisect<br /> <br />bisect is used to insert data to a sorted list<br /> <br />for example: <br />a = [ 1, 5, 8, 100 ]<br />bisect.insort( a, 9 ), then a is 1, 5, 8, 9, 100<br /> <br />bisect.bisect( a, 9 ) => 获取插入点的位置,如果插入9, 那么它的位置是多少<br />原创 2011-02-17 11:48:00 · 424 阅读 · 0 评论