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 ......
ÏÂÃæÕâ¸öС¹¤¾ß°üº¬ÁË ÅжÏunicodeÊÇ·ñÊǺº×Ö£¬Êý×Ö£¬Ó¢ÎÄ£¬»òÕ߯äËû×Ö·û¡£ È«½Ç·ûºÅת°ë½Ç·ûºÅ¡£ unicode×Ö·û´®¹éÒ»»¯µÈ¹¤×÷¡£ »¹ÓÐÒ»¸öÄÜ´¦Àí¶àÒô×ֵĺº×ÖתƴÒôµÄ³ÌÐò£¬»¹ÔÚÕûÀíÖС£
#!/usr/bin/env python
# -*- coding:GBK -*-
"""ºº×Ö´¦ÀíµÄ¹¤¾ß:
ÅжÏunicodeÊÇ·ñÊǺº×Ö£¬Êý×Ö£¬Ó¢ ......
×î½üÒªÓõ½´®¿ÚͨѶ£¬¼òµ¥Ò×ÓõÄ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µÄ×Ö·û´®±àÂëÎÊÌâ
ÔÎijö´¦:http://hi.baidu.com/yobin/blog/item/894158b575090dcb37d3ca07.html
------------------------------------------------------------------
×Ö·û´®±àÂë
pythonÖÐĬÈϱàÂëÊÇASCII£¬¿ÉÒÔͨ¹ýÒÔÏ·½Ê½ÉèÖúͻñÈ¡£º
import sys
print sys.getdefa ......
SleekEngine
Ëæ×żÆËã»úÓ²¼þµÄ¿ìËÙ·¢Õ¹£¬10ÄêǰÒòΪËÙ¶ÈÎÊÌâ¶ø±»Ú¸²¡µÄJavaÏÖÔÚ³ÉÁ˼ÆËã»úÁ÷ÑÔÓïÑÔÖеÄÀϴ󣬵«ÊÇËüÈ´ÈÔ±»ÈÏΪ¸´ÔÓ±¿ÖØ£¬½ü¼¸ÄêÀ´¶¯Ì¬Óï
ÑÔÈ´ÓкóÀ´¸ÏÉϵÄÇ÷ÊÆ£¬ÕÆÎÕÒ»ÃŶ¯Ì¬ÓïÑÔ³ÉÁ˳ÌÐòÔ±ÐèÒª¿¼ÂǵÄÊÂÒË¡£ ½üÆÚ½Ó´¥Á˼¸ÖÖÁ÷ÐеĶ¯Ì¬ÓïÑÔPython, Ruby,
Groovy£¬ËüÃÇÏà±È¾²Ì¬ÓïÑÔJava/C++À´Ëµ£¬´óÎ ......