Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 "------------------------------


Ïà¹ØÎĵµ£º

Google½«ÏÞÖÆPythonÓïÑÔµÄÓ¦Óà ¿ª·¢ÉçÇøÈÈÒé

Google½«ÏÞÖÆPythonÓïÑÔµÄÓ¦Óà ¿ª·¢ÉçÇøÈÈÒé
 
¸ÐлÂ̲ÝÐǿյÄͶµÝ
ÐÂÎÅÀ´Ô´:CSDN
Collin WinterÊÇPythonÉçÇøÒ»Î»ÆÄ¾ßÓ°ÏìÁ¦µÄ¿ª·¢Õߣ¬ËûÔøÊÇCPythonÏîÄ¿µÄºËÐÄ¿ª·¢ÕßÖ®Ò»¡¢Ò²ÔøÊÇUnladen Swallow£¨¼ûÎÄĩעÊÍ£©µÄºËÐÄ¿ª·¢Õߣ¬²ÎÓëÁ˺ܶàPythonÏîÄ¿µÄ¿ª·¢¡£½üÀ´´«ÎÅGoogle½«ÔÚÆäÐÂÏîÄ¿ÖÐÏÞÖÆPythonµÄʹÓã¬Îª´ËÓп ......

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ÖеıàÂë


pythonÖеıàÂë
Ô­ÎÄ£ºhttp://users.ir-lab.org/~liulong/blog/archives/001962.html
¼ÆËã»úÒÔ0,1¶þ½øÖÆÎ»À´´æ´¢ÐÅÏ¢,ËùÒÔ×Ö·ûÔÚ¼ÆËã»úÖеıíʾҲÊǶþ½øÖÆÎ»,ÄÇÿ¸ö×Ö·ûËù¶ÔÓ¦µÄ¶þ½øÖÆÎ»ÊÇʲô,ÔÚ¿ªÊ¼µÄ¼ÆËã»úÖÐÒòΪֻ¿¼ÂÇÓ¢Óï, ËùÒÔ²»³¬¹ý256¸ö×Ö·û,¼´ÓÃÒ»¸ö×Ö½Ú(8bit)¾Í×ã¿ÉÒÔ±íʾËùÓеÄ×Ö·û,Õâ¸ö¶ÔÓ¦¹ØÏµ¾ÍÊǶÔ×Ö·ûµ ......

Python ×Ö·û´®·½·¨Ïê½â


ÀàÐÍ
·½·¨
×¢½â
Ìî³ä
center(width[, fillchar]) ,
ljust(width[, fillchar]),
rjust(width[, fillchar]),
zfill(width),
expandtabs([tabsize])
l        
fillchar ²ÎÊýÖ¸¶¨ÁËÓÃÒÔÌî³äµÄ×Ö·û£¬Ä¬ÈÏΪ¿Õ¸ñ
l        
¹Ë ......

PythonÎļþ²Ù×÷


Îļþ²Ù×÷ÊdzÌÐòÉè¼ÆÖв»¿É»òȱµÄÖØÒª²¿·Ö¡£Pythonͨ¹ýÒ»¸öÄÚÖú¯ÊýopenÀ´´ò¿ªÎļþ¡£
     open(filename,mode,buffer)
     ÆäÖеÚÒ»¸ö²ÎÊýÊÇÒª´ò¿ªµÄÎļþµÄÎļþÃû£¬±ØÑ¡£»µÚ¶þ¸öÊÇ´ò¿ª·½Ê½£¬¿ÉÑ¡£»µÚÈý¸öΪ»º³åÇø£¬¿ÉÑ¡¡£Ä¬ÈÏÇé¿öÏÂÊÇÒÔ“¶Á”ģʽ´ò¿ªÎļþ¡£¸Ãº¯Êý ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ