Time of Update: 2015-06-22
標籤:一. install python1) check install or not在mac終端輸入命令:which python 即可查看python的路徑2)未安裝時,手動下載安裝包 地址:https://www.python.org/downloads/ 選擇下載 Mac OS X 64-bit/32-bit installer 安裝二. install twisted1) check install
Time of Update: 2015-06-23
標籤:第1章:文本1:每次處理一個字元1:內建函數listthelist=list(string)2:for遍曆for i in string:pass3:列表解析[i for i in string]4:通過sets模組來解決這個問題import setschar=sets.Set(‘abcdeabcd‘)char1=sets.Set(‘subprocessabcdexyzabcdxyz‘)print
Time of Update: 2015-06-23
標籤:python hbase thrift網關 #pythonfrom thrift import Thriftfrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocolfrom hbase import
Time of Update: 2015-06-23
標籤:python 程式設計語言 threading模組提供了進階別的線程介面,基於低層級的_thread模組實現。模組基本方法該模組定了的方法如下:threading.active_count() 返回當前活躍的Thread對象數量。返回值和通過enumerate()返回的列表長度是相等的。threading.current_thread()
Time of Update: 2015-06-23
標籤:python uuid 1. 下載uuid模組https://pypi.python.org/pypi/uuid/uuid-1.30.tar.gz2. 解壓uuid模組tar zxvf uuid-1.3.0.tar.gz -C /usr/src3. build模組cd /usr/src/uuidpython setup.py build4. install模組python setup.py install函數用法uuid.
Time of Update: 2015-06-23
標籤:python 多線程 編程 lock 1、threading 模組中的內容 - Thread: 一個可執行線程對象 - Lock: 原始的Lock對象 與thread模組中一樣 - RLock: 允許單個線程多次請求的Lock - Condition: 線程等待直到條件滿足 - Event :
Time of Update: 2015-06-23
標籤:對於伺服器來說建立TCP串連的過程分為4步:1.建立socket對象:這裡與用戶端一樣,依然是:s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)2.設定和得到socket選項python定義了setsockopt()和getsockopt(),一個是設定選項,一個是得到設定。這裡主要使用setsockopt(),具體結構如下:setsockopt(level,optname,value)level定義了哪個選項將被使用。通常情況下是SOL
Time of Update: 2015-06-23
標籤:1.擷取目前時間的兩種方法: import datetime,timenow = time.strftime("%Y-%m-%d %H:%M:%S")print nownow = datetime.datetime.now()print now2.擷取上個月最後一天的日期(本月的第一天減去1天) last = datetime.date(datetime.date.today().year,datetime.date.today().month,1)-datetime.
Time of Update: 2015-06-23
標籤:有時候難免需要直接調用Shell命令來完成一些比較簡單的操作,比如mount一個檔案系統之類的。那麼我們使用Python如何調用Linux的Shell命令?下面來介紹幾種常用的方法:1. os 模組 1.1. os模組的exec方法族Python的exec系統方法同Unix的exec系統調用是一致的。這些方法適用於在子進程中調用外部程式的情況,因為外部程式會替換當前進程的代碼,不會返回。( 這個看了點 help(os) --> search
Time of Update: 2015-06-23
標籤:python 多線程 編程 thread 1、使用thread模組(不推薦) 常用函數: ‘start_new_thread(function,args,kwargs=None)’:建立一個新的線程,並運行’function(args)’ ‘allocate_lock()’: 建立鎖對象 Lock object ‘exit()’: 提示線程退出
Time of Update: 2015-06-23
標籤:最近在看《Flask Web開發基於Python的Web應用開發實戰》Miguel Grinberg著、安道譯 這本書,一步步跟著學習Flask架構的應用,這裡做一下筆記電腦只安裝一個Python2.7就行了,用的IDE還是官方那個跟記事本差不多的編輯器,先原始一點,以後再用PyCharm開發,我系統是Win8.1 x64一:虛擬環境配置 虛擬環境使用第三方工具virtualenv建立,開啟cmd,輸入virtualenv命令來檢測是否已經安裝,我已經裝過了,所以會提示:You
Time of Update: 2015-06-23
標籤:python82.file()和open()具有相同的功能,可以任意替換。 83.UNS通用分行符號支援 84.python2.3之後使用迭代器的效率比xreadlines高 85.標準檔案(標準輸入、標準輸出(緩衝輸出)、標準錯誤(非緩衝輸出)),只要程式執行就可以訪問,這些檔案已經預先打卡。sys.sdtin sys.stdout sys.stderr 86.使用getopt和optparse來處理常式參數問題 87.異常的類型:NameError、ZeroDivisionError、
Time of Update: 2015-06-23
標籤:所有Python原始碼檔案都使用副檔名 .py。當運行.py檔案時,Python會自動建立相應的.pyc檔案。.pyc檔案包含目標代碼。看下面一個簡單程式:#name.pyname=input(‘what is your first name?‘)print(‘hello ‘+name.capitalize()+‘!‘)第一行是原始碼注釋,python注釋總是以符號#打頭,並延續到行尾。第二行調用函數input,這是用於從鍵盤讀取字串的標準內建函數。這行代碼執行時,將在輸出視窗中顯示
Time of Update: 2015-06-22
標籤:logging中RotatingFileHandler和TimedRotatingFileHandler對於多進程不支援(由於每個進程都保持一個固定的檔案控制代碼,導致在達到條件復原時,相互之間的rename會相互幹擾,比如一個進程已經把worker.log變為worker.log.2016-06-01了,其他進程就跟著寫到worker.log.2016-06-01了,其他還有好多問題) 故實現適應多進程的handle,代碼如下: # -*- coding:
Time of Update: 2015-06-22
標籤:目標:下載貼吧或空間中所有圖片步驟:(1)擷取頁面代碼 (2)擷取圖片URL,下載圖片代碼如下:#!/usr/bin/pythonimport reimport urllibdef getHtml(url): page=urllib.urlopen(url) html=page.read() return hemldef getImg(html): reg=r‘src="(.*?\.jpg" width‘ imgre=re.compile(reg)
Time of Update: 2015-06-22
標籤:如何對dict類型按鍵(keys)排序(Python 2.4 或更高版本):mydict = {‘carl‘:40, ‘alan‘:2, ‘bob‘:1, ‘danny‘:3}for key in sorted(mydict.iterkeys()): print "%s: %s" % (key, mydict[key])結果:alan: 2bob: 1carl: 40danny: 3摘自 Python
Time of Update: 2015-06-22
標籤:1、簡單的Regeximport res=r‘abc‘re.findall(s,"aaaaaaaaaaaaaaa") #結果為[]re.findall(s,"abcaaaaaaaaaaaa") #結果為[‘abc‘]re.findall(s,"abcaaaaaabcaaaa") #結果為[‘abc‘,‘abc‘]2、元字元[] :指定一個字元集 例如:r‘t[io]p‘ 滿足的字串包括‘tip‘或‘top‘ 加上^表示取反
Time of Update: 2015-06-22
標籤:To change a sequence you are iterating over while inside the loop (for example to duplicate certain items), it is recommended that you first make a copy. Looping over a sequence does not implicitly make a copy. The slice notation makes this
Time of Update: 2015-06-22
標籤:python 編程 學習《Python核心編程》做一下知識點提要,方便複習。電腦語言的本質是什嗎? a-z、A-Z、符號、數字等等組合成符合文法的字串,供編譯器、解譯器翻譯。 字母組合後產生各種變化拿python來說就是,關鍵字,數值,類,函數,運算子,操作符。。。。。。1.變數不用聲明,類型不固定 2.True,False = False,True讀出了什嗎?True是個bool()類執行個體
Time of Update: 2015-06-23
Windows 下安裝Python包(Numpy)的錯誤:Unable to find vcvarsall.bat,numpyvcvarsall.bat情景簡介: Windows 環境下安裝Python2.7的Numpy擴充包時提示:error: Unable to find vcvarsall.bat 經過不懈的Google/Bing,發現不僅安裝Numpy時會出現這種情況,安裝其他Python包時也可能出現這種情況。Windows 7 64bitPython 2.7Numpy-1.9.2