Eric Florenzano给大家带来了一篇非常不错的文章《Gems of Python》
这里还有一篇 Python gems of my own
其中有一个非常neat的正则表达式调试技巧:
128I don't know if this is documented in the Official python documentation, but it is an incredibly useful regex debugging tool. You can pass in 128 to your re.compile() function and get the parse tree back out! Really neat, check it out:
>>> import re
>>> re.compile('(\w+): (<.*?>)', 128)
subpattern 1
max_repeat 1 65535
in
category category_word
literal 58
literal 32
subpattern 2
literal 60
min_repeat 0 65535
any None
literal 62
<_sre.SRE_Pattern object at 0x29f278>
>>> re.compile('Ahoy Globe', 128)
literal 65
literal 104
literal 111
literal 121
literal 32
literal 71
literal 108
literal 111
literal 98
literal 101
<_sre.SRE_Pattern object at 0x267920>
原因是 re.DEBUG == 128
最后这里有一篇不错的文章:unzip un-needed in Python 。为什么python里有zip()函数没有unzip()函数呢?
首先要说说python函数传递参数时候的unpack。
那么剩下来的事情就很简单啦。
>>> t1 = (0,1,2,3)
>>> t2 = (7,6,5,4)
>>> [t1,t2] == zip(*zip(t1,t2))
True
python真的比较有趣
Comments