為防止log日誌過大,每隔一小時就會把重新寫log檔案,而之間的檔案則重新命名為server_errors.log.yyyy-dd-mm-nn,其中nn為序號,從00到23.鑒於我們log的基本形式,我們要分析的不僅僅是errors.log,還需要分析其他當天產生的檔案,這就需要一個方法去取得這些檔案的列表。開始的時候,準備通過glob模組來取得檔案清單,glob根據給定模式產生滿足該模式的檔案名稱列表, 和 Unix shell 相同. for eachfile in glob.glob(r"
為了全面測試一個Web系統,我們需要與系統UI相互動並做出相應的斷言。最常用的互動是通過selenium.py中以下方法來實現的:open(url): Opens an URL in the test frame. This accepts both relative and absolute URLs. click(locator): Clicks on a link, button, checkbox or radio button. If the click action causes
The last character in a raw string can’t be a backslash, If the last character(before the final quote) is a backslash, Python won’t know whether to end the string or not.raw字串最後一個字元不能是\如果確實需要最後一個字元是\,需要將\放到另外一個字串裡>>> print r"c:\Prpgram
#-------------------------------------------------------------------------------# Name: ChangeFilesExtension# Purpose: Try to change extension of a file from one to others## Author: ankier## Created: 30/08/2012# Copyright: (c)
代碼很簡單,不到5k行。但是思路挺好的,改成non-blocking了之後效率就是能提高不少,特別是考慮到現代的web app都需要和其他的HTTP伺服器通訊,blocking的代價太大了。Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed. The FriendFeed application is written using a
因為能及時地完成這個小工具,全靠在網上找到一些代碼來用,所以,也把自己完成的東西回饋給網路。:)之前有這麼一個小需求,要大量地翻譯一些零散的句子,對於翻譯的品質並不在意,直接採用翻譯工具的結果就可以了。但是量很大,於是就想著用 Google 的翻譯 API 來做。一開始想用 JavaScript 來寫的,但由於只會 JavaScript 的對 Google 翻譯 API 的非同步呼叫方式,不知道如何才能進行批量的翻譯。於是決定用 Python
將晦澀難懂的測試分解成簡單的測試本篇的目的是解說晦澀的測試不易一目瞭然,然後用一個例子將晦澀的測試案例化為簡單的測試案例,使得測試結果一目瞭然。Breaking down obscure tests into simple ones.Unittest provides the means to test the code through a series of assertions. I have often feltthe temptation to exercise many