google protocol buffer好用,但是在python中會有一些小問題。比如不支援utf-8隻支援unicode的字串。在我們的系統中,儲存的和傳輸的都是utf-8,因此在代碼中(c++,java,python)都統一使用utf-8格式。所以就帶來不方便,比如c++中需要從utf-8轉為unicode,python中再解析出來。實際上,可以讓google protocol buffer for
作者:Shane出處:http://bluescorpio.cnblogs.com lxml takes all the pain out of XML. Stephan Richter lxml是Python語言裡和XML以及HTML工作的功能最豐富和最容易使用的庫。lxml是為libxml2和libxslt庫的一個Python化的綁定。它與眾不同的地方是它兼顧了這些庫的速度和功能完整性,以及純Python API的簡潔性,大部分與熟知的ElementTree API相容但比之更優越。
python的SocketServer代碼記錄,這個是從網上摘抄下來經自己改寫了一點的,客戶測試端自己寫的!server:import SocketServerclass RequestHandler(SocketServer.StreamRequestHandler): def handle(self): while True: mdata = self.request.recv(1024) if not mdata: break else:
情景:計算記錄檔中,獨立IP的個數,也就是unique visitor。計算量:每小時大概有70萬左右的記錄,每天24小時,大概1400-1500萬條記錄 一開始,想到用一個list來儲存用戶端IP,從日誌裡邊取出一個IP,判斷是否已經存在,如果存在,就忽略,否則添加到這個list中去addrs = [] for line in f.readlines() : addr = get_addr(line) if not addr in addrs :
函數:getpass.getuser() 解釋: Return the “login name” of the user. Availability: Unix, Windows. This function checks the environment variables LOGNAME, USER, LNAME and USERNAME, in order, and returns the value of the first one which is set to a non-
1、NameError:嘗試訪問一個未申明的變數>>> vNameError: name 'v' is not defined2、ZeroDivisionError:除數為0 >>> v = 1/0ZeroDivisionError: int division or modulo by zero3、SyntaxError:語法錯誤 >>> int intSyntaxError: invalid syntax