我对python和bencoding是个新手。我需要使用python为我的项目读写torrent文件。我已经导入了模块,下面是解析torrent的代码:
下面是我的模块http://paste2.org/p/1442120的链接,它是http://pypi.python.org/pypi/BitTorrent-bencode/5.0.8.1的一个模块
import sys
from bencode import *
f = open('file.torrent','rb') #binary read write
for line in f:
print line,
print bdecode(line)如果我理解正确,bdecode函数一次需要一个值,但是我如何解析torrent文件呢?或者..。
发布于 2011-05-29 21:30:02
问题是Bencoded文件不是面向行的文件。你所做的就像拿一份报告,把它放在碎纸机里,然后一次一份地交给你的老板。以下是对Bencoded文件进行解码的正确方法:
import bencode
print bencode.bdecode(open('file.torrent', 'rb').read())https://stackoverflow.com/questions/6167823
复制相似问题