Time of Update: 2015-05-18
標籤:接觸了Ruby,發現它有個包管理工具RubyGem非常好用,而且有非常完備的文檔系統http://rdoc.info發現Python下也有相同的工具,包含easy_install和Pip。只是,我沒有細看easy_install的方法,這就簡單的介紹一下Pip的安裝與使用:準備:$ curl -O http://python-distribute.org/distribute_setup.py$ python distribute_setup.py安裝:$ curl -O https://
Time of Update: 2015-05-18
標籤:time ctime asctime strftime strptime從time 模組的協助文檔中,發現相關的函數主要有如下: time() -- return current time in seconds since the Epoch as a float clock()&
Time of Update: 2015-05-16
標籤:python 函數 http://blog.csdn.net/pipisorry/article/details/45771045python內建函數枚舉函數enumerate>>> list(enumerate(‘abc‘))[(0, ‘a‘), (1, ‘b‘), (2, ‘c‘)]enumerate函數還可以接收第二個參數。>>> list(enumerate(‘abc‘, 1))
Time of Update: 2015-05-17
標籤:首先搭建基本環境,假設已經有Python運行環境。然後需要裝上一些通用的基本庫,如numpy,
Time of Update: 2015-05-18
標籤:輸入:ex10raw_input("Name? ")查看協助文檔:ex12python -m pydoc raw_input匯入模組:ex13from sys import argv解包:ex13script, first, second, third = argv運行時,需要多個參數 讀取檔案:ex15txt = open(filename)print "Here‘s your file %r:" % filenameprint
Time of Update: 2015-05-17
標籤:milang python 本函數是實現訪問父類或兄弟類對象,是返回一個代理類對象,以便訪問父類或兄弟類的方法。使用這個函數主要用來避免在繼續類時使用基類的類名稱,以及多重繼承時,保證只調用一次基類的建構函式。要注意點就是不能與調用基類名稱方式混合使用。例子:#super()class A: def __init__(self): print(‘A.init‘)class B(A): def __
Time of Update: 2015-05-14
標籤:書在這裡 Selenium is a set of tools for automating browsersSelenium IDE: This is a Firefox add-in used to record and play back the Selenium scripts with Firefox.Selenium WebDriver: This is a programming interface for developing advanced Selenium
Time of Update: 2015-05-14
標籤:在 web ui 自動化測試中,frame 一直是令人頭痛的問題,就像上班必須擠公車坐地鐵一般,frame 的問題總是令人氣悶糾結為之黯然神傷。以前在使用 Selenium1 的時候,frame 也是頗為棘手的一個問題。不但要照本宣科的進行一系列的設定,而且在進行實際代碼編寫的過程中會遇到各種奇奇怪怪的問題。 frame 就像中國男足的後防線,問題多多難以解決。selenium webdriver 處理 frame 比較簡單,這點比某些測試載入器要先進一些,令人身心愉悅。以下面的
Time of Update: 2015-05-14
標籤:新式類和舊式類 python的新式類是2.2版本引進來的,我們可以將之前的類叫做經典類或者舊類。 為什麼要在2.2中引進new style class呢?官方給的解釋是: 為了統一類(class)和類型(type)。 在2.2之前,比如2.1版本中,類和類型是不同的,如a是ClassA的一個執行個體,那麼a.__class__返回 ‘ class __main__.ClassA‘ ,type(a)返回總是<type ‘instance‘&
Time of Update: 2015-05-13
標籤:#hello.pydef sayHello(): str="hello" print(str);if __name__ == "__main__": print (‘This is main of module "hello.py"‘)
Time of Update: 2015-05-14
標籤:python#!/usr/bin/pythonfrom time import clockl = [(x,x) for x in xrange (10000000)] d = dict(l) t0 = clock() # 方法一for i in d: n = d[i]t1 = clock() # 方法二:最慢for k,v in d.items(): n = vt2 = clock() # 方法三: 最快,推薦方法for k,v in d.iteritems():
Time of Update: 2015-05-13
標籤:1.常用內建函數:(不用import就可以直接使用) help(obj) 線上協助, obj可是任何類型 callable(obj) 查看一個obj是不是可以像函數一樣調用 repr(obj) 得到obj的表示字串,可以利用這個字串eval重建該對象的一個拷貝 eval_r(str)
Time of Update: 2015-05-13
標籤:map python 利用map()函數,把使用者輸入的不規範的英文名字,變為首字母大寫,其他小寫規範名字。例如輸入:[‘adam‘, ‘LISA‘, ‘barT‘],輸出:[‘Adam‘, ‘Lisa‘, ‘Bart‘]。
Time of Update: 2015-05-14
標籤: #擷取指令碼所在目錄 print os.path.split( os.path.realpath( sys.argv[0] ) )[0] #擷取指令碼運行目錄 print os.getcwd() 本地目錄讀取
Time of Update: 2015-05-12
標籤:在編碼中牽扯到時間問題的時候,總是容易被時區問題搞混,一直以來,都是反覆實驗應付過去,今天終於搞清楚了個中緣由,一個心結也得以化解。Python 的時區問題datetime.today() / datetime.now()這兩個函數獲得的是當前的系統時間,但得到的datetime對象中的tzinfo是空的,即使系統中設定了時區。datetime.utcnow()這個函數獲得當前的utc時間,應該是根據當前系統時間和時區來計算的。例如系統時間為14:00,時區為 Asia/Shanghai
Time of Update: 2015-05-12
標籤:python 源碼 基礎 python源碼剖析筆記1——Python對象初見
Time of Update: 2015-05-11
標籤:1 24點簡介 拿一副牌,抽去大小王后(初練也可以把J/Q/K也拿去),剩下1~10這40張牌(以下用1代替A)。任意抽取4張牌(稱為牌組),用加、減、乘、除 (可加括弧)把牌面上的數算成24。每張牌必須且只能用一次。如抽出的牌是3、8、8、9,那麼算式為(9-8)×8×3=24。 解決本問題兩種常見思路: 1. 運算式加括弧。可以選擇:不加括弧,1個括弧,2個括弧。 2. 逆波蘭運算式。 2 逆波蘭運算式 逆波蘭運算式又叫做尾碼運算式。
Time of Update: 2015-05-11
標籤:找到最大或者最小的N個元素heapq模組有兩個函數–nlargest()和nsmallest()正好能解決我們的問題。>>> print(heapq.nlargest(3, nums))[43, 23, 8]>>> print(heapq.nsmallest(3,nums))[-1, 1, 2]#anotherimport heapqportfolio = [ {‘name‘: ‘IBM‘, ‘shares‘: 100, ‘price‘: 91.1}
Time of Update: 2015-05-11
標籤:python1 python語言中對象的類型和記憶體都是運行時確定的。在建立也就是賦值時,解譯器會根據文法和右側的運算元來決定新對象的類型。2 GAE 英文全稱為 Google App Engine。它是 Google 管理的資料中心中用於 WEB 應用程式的開發和託管的平台,目前支援python、java和php開發 3.HTTPError: HTTP Error 403: Forbiddenimport sys,urllib2req =
Time of Update: 2015-05-10
標籤:python pil 驗證碼 第 0010 題:使用 Python 產生類似於中的字母驗證碼圖片閱讀資料思路:先隨機產生驗證碼,然後用Python的PIL庫畫出這個啟用碼的圖片,具體點就是建立畫布,加驗證碼的字上去,增加噪點進行幹擾,再進行模糊處理,接著儲存到名字為驗證碼的圖片中。0010.產生驗證碼圖片.py#!/usr/bin/env python#coding: