易截截图软件、单文件、免安装、纯绿色、仅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 中文乱码 问题深入分析

 
转自:http://hi.baidu.com/%C1%EE%BA%FC%CF%F3/blog/item/efb76fb7f0411dc437d3ca20.html
 
在本文中,以'哈'来解释作示例解释所有的问题,“哈”的各种编码如下:
  1. UNICODE (UTF8-16),C854;
  2. UTF-8,E59388;
  3. GBK,B9FE。
一、python中 ......

python 判断是不是中文字

 下面这个小工具包含了 判断unicode是否是汉字,数字,英文,或者其他字符。 全角符号转半角符号。 unicode字符串归一化等工作。 还有一个能处理多音字的汉字转拼音的程序,还在整理中。
 
#!/usr/bin/env python
# -*- coding:GBK -*-
"""汉字处理的工具:
判断unicode是否是汉字,数字,英 ......

Python完全新手教程

作者:taowen, billrice
http://www.cnblogs.com/taowen/articles/11239.html
Lesson 1 准备好学习Python的环境
下载的地址是:
www.python.org
为了大家的方便,我在校内作了copy:
http://10.1.204.2/tool/compiler&IDE/Python-2.3.2-1.exe
linux版本的我就不说了,因为如果你能够使用linux并安装好说明你可以 ......

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语言。   太高深的资料看不懂,当了本最简单的Python简明教程,中文版chm格式的。不说废话了,开始进入Python的世界吧。 (一)安装Python    写这篇文章时,Python的最新版本是3.1,我喜欢用最新的,就下了新版本的。一路Next下去,我的C ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号