易截截图软件、单文件、免安装、纯绿色、仅160KB

Python脚本解析BitTorrent种子文件内容

有很多种子文件,有时候记不清里面都是什么东西,又不想一个一个的拖放到迅雷或BT软件里头看,
上网查了一下Python的脚本,自己也稍微修改了一下,代码如下,粘贴到文本编辑器中(最好是带格式的如UltraEdit或VS2008等):
保存成py后缀的,直接运行
import re
def tokenize(text, match=re.compile("([idel])|(\d+):|(-?\d+)").match):
i = 0
while i < len(text):
m = match(text, i)
s = m.group(m.lastindex)
i = m.end()
if m.lastindex == 2:
yield "s"
yield text[i:i+int(s)]
i = i + int(s)
else:
yield s
def decode_item(next, token):
if token == "i":
# integer: "i" value "e"
data = int(next())
if next() != "e":
raise ValueError
elif token == "s":
# string: "s" value (virtual tokens)
data = next()
elif token == "l" or token == "d":
# container: "l" (or "d") values "e"
data = []
tok = next()
while tok != "e":
data.append(decode_item(next, tok))
tok = next()
if token == "d":
data = dict(zip(data[0::2], data[1::2]))
else:
raise ValueError
return data
def decode(text):
try:
src = tokenize(text)
data = decode_item(src.next, src.next())
for token in src: # look for more tokens
raise SyntaxError("trailing junk")
except (AttributeError, ValueError, StopIteration):
raise SyntaxError("syntax error")
return data
if __name__ == "__main__":
#需要读取的文件名称放到这里
data = open("Riko.Tachibana.torrent", "rb").read()
torrent = decode(data)
myfile = file("testit.txt", 'w')
a = u'文件名称'.encode('gbk')
b = u'文件大小'.encode('gbk')
print "%s \t %s \n" % (a,b)
for file in torrent["info"]["files"]:
print "%s \t %d Mb " % ("/".join(file["path"]), file["length"]/1024/1024)
print "------------------------------


相关文档:

Python字符串操作

 #Python字符串操作
''
'1.复制字符串'
''
#strcpy(
sStr1,
sStr2)
sStr1 =
'strcpy'
sStr2 =
sStr1
sStr1 =
'strcpy2'
print
sStr2
''
'2.连接字符串'
''
#strcat(
sStr1,
sStr2)
sStr1 =
'strcat'
sStr2 =
'append'
sStr1 +
=
sStr2
print
sStr1
''
'3.查找字符'
''
#strc ......

Python的串口通讯第三方库PySerial

 最近要用到串口通讯,简单易用的Python又帮上忙了,多亏了庞大的第三方资源~~~ :)
pySerial
Overview
This module encapsulates the access for the serial port. It provides
backends for Python running on Windows, Linux, BSD (possibly any POSIX
compliant system), Jython and IronPython (.NET and M ......

Python字符集编码和文件读写

 这篇文章讲得比较清楚python的字符串编码问题
原文出处:http://hi.baidu.com/yobin/blog/item/894158b575090dcb37d3ca07.html
------------------------------------------------------------------
字符串编码
python中默认编码是ASCII,可以通过以下方式设置和获取:
import sys
print sys.getdefa ......

python os 模块

Python 3 教程二:文件,目录和路径
http://www.cnitblog.com/yunshichen/archive/2009/04/01/55931.html
python os模块
http://hi.baidu.com/happynp/blog/item/729243f902d5a751242df2c2.html
http://hi.baidu.com/fiber212121/blog/item/6e07ec03c97b6982d53f7c27.html
python getopt模块
http://www.tsnc.edu.cn/de ......

Python 拷贝对象(深拷贝deepcopy与浅拷贝copy)

>>> import copy
>>> a = [1,2,3,4,['a','v']]
>>> b = a
>>> b
[1, 2, 3, 4, ['a', 'v']]
>>> c = copy.copy(a)
>>> c
[1, 2, 3, 4, ['a', 'v']]
>>> d = copy.deepcopy(a)
>>> d
[1, 2, 3, 4, ['a', 'v']]
>>> a.append(5) ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号