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 "------------------------------
Ïà¹ØÎĵµ£º
http://hbszyandong.javaeye.com/blog/377199
# -*- coding: utf-
8
-*-
from datetime import
datetime
from datetime import
date
from time import
strftime
from time imp ......
×î½üÒªÓõ½´®¿ÚͨѶ£¬¼òµ¥Ò×ÓõÄ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¼òÃ÷½Ì³Ì£¬ÖÐÎİæchm¸ñʽµÄ¡£²»Ëµ·Ï»°ÁË£¬¿ªÊ¼½øÈëPythonµÄÊÀ½ç°É¡£ £¨Ò»£©°²×°Python дÕâÆªÎÄÕÂʱ£¬PythonµÄ×îа汾ÊÇ3.1£¬ÎÒϲ»¶ÓÃ×îÐµģ¬¾ÍÏÂÁËа汾µÄ¡£Ò»Â·NextÏÂÈ¥£¬ÎÒµÄC ......
pythonÖеıàÂë
ÔÎÄ£ºhttp://users.ir-lab.org/~liulong/blog/archives/001962.html
¼ÆËã»úÒÔ0,1¶þ½øÖÆÎ»À´´æ´¢ÐÅÏ¢,ËùÒÔ×Ö·ûÔÚ¼ÆËã»úÖеıíʾҲÊǶþ½øÖÆÎ»,ÄÇÿ¸ö×Ö·ûËù¶ÔÓ¦µÄ¶þ½øÖÆÎ»ÊÇʲô,ÔÚ¿ªÊ¼µÄ¼ÆËã»úÖÐÒòΪֻ¿¼ÂÇÓ¢Óï, ËùÒÔ²»³¬¹ý256¸ö×Ö·û,¼´ÓÃÒ»¸ö×Ö½Ú(8bit)¾Í×ã¿ÉÒÔ±íʾËùÓеÄ×Ö·û,Õâ¸ö¶ÔÓ¦¹ØÏµ¾ÍÊǶÔ×Ö·ûµ ......
ÀàÐÍ
·½·¨
×¢½â
Ìî³ä
center(width[, fillchar]) ,
ljust(width[, fillchar]),
rjust(width[, fillchar]),
zfill(width),
expandtabs([tabsize])
l
fillchar ²ÎÊýÖ¸¶¨ÁËÓÃÒÔÌî³äµÄ×Ö·û£¬Ä¬ÈÏΪ¿Õ¸ñ
l
¹Ë ......