Time of Update: 2018-12-04
今天說到全域變數和本地變數,老外老師說了,全域變數就好像好萊塢的明星一樣,每個人都知道。而本地變數需要聲明才能用,不然人們不知道。 #The function,jennifer is local def God(); global Jennifer Jennifer='pretty' #Main program,always global,Hollywood becomes famous,and everybody knows God() print Jennifer
Time of Update: 2018-12-04
這裡主要寫一些關於Python語言本身有關的檔案 1>*.py 這是最常用的,也是萬能的Python檔案格式.在*.py中儲存了文字格式設定的Python代碼,在運行時,可以由Python解譯器載入代碼,將其即時解釋為機器碼進行執行,不過要注意的是*.py是基於命令列的,因此在運行時會出現一個命令列終端.2>*.pyw 這裡的代碼和*.py是一樣的,不過是基於GUI的,執行時不帶命令列終端.3>*.pyc
Time of Update: 2018-12-04
python一句代碼幹掉你三天良性睡眠(關於代碼縮排) 需求:一個大學裡提供一門課程,讓學生參加資格考試,考完之後,學校想知道自己學生在考試時的表現,如果通過率高,就增加學費。現在,要求寫一個程式,對考試結果進行總結。這裡假設有10個學生,1表示該學生通過了考試,2表示沒有通過。 1.輸入每個考試結果(1或2)。每次請求另一個考試結果時,都在螢幕上顯示訊息:“Enter result”。 2.統計兩類考試結果的數量(1的數量和2的數量)。
Time of Update: 2018-12-04
利用selenium工具,可支援多種瀏覽器。網上資料比較多。經過比較,我選擇了Splinter模組,因為利用Splinter開發瀏覽器自動化操作,編寫代碼比較簡單。一、Splinter的安裝Splinter的使用必修依靠Cython、lxml、selenium這三個軟體。所以,安裝前請提前安裝Cython、lxml、selenium。以下給出連結地址:1)http://download.csdn.net/detail/feisan/43012932)http://code.google.com/
Time of Update: 2018-12-04
opencv_haystack =cv2.imread('woman2.bmp')opencv_needle =cv2.imread('face.bmp')ngrey = cv2.cvtColor(opencv_needle, cv2.COLOR_BGR2GRAY)hgrey = cv2.cvtColor(opencv_haystack, cv2.COLOR_BGR2GRAY)# build feature detector and descriptor
Time of Update: 2018-12-04
Twitter 的API有很多,但是總感覺不給力,總是扣扣索索不給你給全了。我總結了下,寫了幾個API如下code:'''Created on Jun 22, 2013@author: Yang'''import twitterimport jsonimport timeimport datetimefrom email.utils import parsedateimport math# Consumerkey = 'myY0zZaRQ1eDEELFfoen7g'#
Time of Update: 2018-12-04
subprocess.call(args,*,stdin=None, stdout=None, stderr=None, shell=False)在內部呼叫下面的函數,所有參數原封不動傳過去class subprocess.Popen(args,bufsize=0,executable=None, stdin=None, stdout=None,stderr=None,preexec_fn=None, close_fds=False, shell=False,cwd=None,env=None,
Time of Update: 2018-12-04
python中struct.unpack的用法4/25/2009 12:18:21 PMPython中按一定的格式取出某字串中的子字串,使用struck.unpack是非常高效的。1. 設定fomat格式,如下:# 取前5個字元,跳過4個字元華,再取3個字元format = '5s 4x 3s'2. 使用struck.unpack擷取子字串import struct print struct.unpack(format, 'Test astring')#('Test',
Time of Update: 2018-12-04
我曾經看過一段python 代碼。就是元類裡面的函數返回了一個類。我百思不得其解。為什麼要這麼做呢?通過調試我終於明白為什麼這麼做了。>>> class test(type):... pass... >>> class test1(test):... def fun (cls, count):... print count... >>> class test2(object):...
Time of Update: 2018-12-04
eval(str [,globals [,locals ]])函數將字串str當成有效Python運算式來求值,並返回計算結果。同樣地, exec語句將字串str當成有效Python代碼來執行.提供給exec的代碼的名稱空間和exec語句的名稱空間相同.最後,execfile(filename [,globals [,locals ]])函數可以用來執行一個檔案,看下面的例子:>>> eval('3+4')7>>> exec
Time of Update: 2018-12-04
轉載:http://ipython.iteye.com/blog/1136931在python這pymmseg-cpp 還是十分方便的! 環境 ubuntu10.04 , python2.65 步驟:1 下載mmseg-cpp的原始碼 http://code.google.com/p/pymmseg-cpp/2 tar -zxf pymmseg-cpp*.tar.gz //解壓後得到pymmseg 目錄 cd pymmseg\mmseg-cpp python
Time of Update: 2018-12-04
>>> import thisThe Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than
Time of Update: 2018-12-04
I predict that in time it will be seen as one of the more powerful features in the language. The problem is that all the introductions to decorators that I have seen have been rather confusing, so I will try to rectify that here.(This series of
Time of Update: 2018-12-04
在WINDOWS上將Python 檔案轉為(產生)可執行程式 exe 檔案閑話就不多說了,需要 Python 2.5 + Py2exePy2exe (http://sourceforge.net/projects/py2exe/files/) (直接安裝即可)步驟如下:1.編譯你的Py檔案,確保無誤,儲存到…(例如:C:/old/test.py ) 2.編輯一個內容如下的py檔案,將其儲存為(例如:C:/old/go.py) from distutils.core import setup
Time of Update: 2018-12-04
要在Windows平台的Apache中使用Python,當然必須得先安裝Apache和Python。Apache我使用的是XAMPP,而Python則隨便一搜,就可以找到下載連結。由於這個解決方案要通過安裝Apache模組mod_python來實現,而mod_python的目前的版本3.3.1隻支援Apache 2.2和Python 2.5,所以不得不先缷載已經裝好的Python 3.0,重新下載安裝了Python
Time of Update: 2018-12-04
9–15. 複製檔案. 提示輸入兩個檔案名稱(或者使用命令列參數 ). 把第一個檔案的內容複寫到第二個檔案中去. #filename:test9-15.pydef copyfile(): fs=raw_input("source file:").strip() #fd=raw_input("destination file:").strip() fd="G:\\copy.txt" fsp=open(fs,'r') fdp=open(fd,'w') for
Time of Update: 2018-12-04
該指令碼的主要是從網上抓取資源存入本地檔案 指令碼中Retriever 類的責任是從 Web 下載頁面,解析每個文檔中的連結並在必要的時候把它們加入 “to-do”隊列。我們為每個從網上下載的頁面都建立一個 Retriever 類的執行個體。Retriever 中的方 法展現了它的功能:構造器(__init__())、filename()、download()、和parseAndGetLinks()。
Time of Update: 2018-12-04
文章目錄 1.1 函數程式設計工具 1 列表列表資料類型還有其它一些方法。下面是列表對象的所有方法:insert(i, x) ---- 在指定位置插入一項。第一自變數是要在哪一個元素前面插入,用下 標表示。例如,a.insert(0, x)在列表前面插入,a.insert(len(a), x)等價於a.append(x) 。append(x) ---- 等價於a.insert(len(a), x)index(x) ----
Time of Update: 2018-12-04
1.模組介面 a.方法: connect(parameters...) 建立一個資料庫連接,返回Connection對象 可能的參數有: dsn 資料來源名稱 user 使用者名稱 password 密碼 host 主機名稱 database 資料庫名 b.常量 apilevel 字串常量,用於指明支援的DB API 版本.目前僅僅允許 "1.0" 和 "
Time of Update: 2018-12-04
近來在學慣用Python作些影像處理的工作,不斷被Python開發的高效率所震撼,而且也感覺到了開發人員對運行期效率的重視,不僅在我使用2.5版本時明顯感到比原來的2.4版本效率高,就連PIL的新版本中也針對映像的像素操作效率進行了很大的改善。 PIL中效率的改善主要來自於Image模組中的load函數,這個函數是在PIL 1.1.6版本中新增加的,相比於原來的getpixel與putpixel函數,主要的目的就是通過提供映像的快取作業對象,提高對映像資料讀寫操作的效率。