Time of Update: 2018-12-05
來源地址:http://snipperize.todayclose.com/snippet/py/python%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%97%A5%E6%9C%9F%E5%89%8D%E5%90%8EN%E5%A4%A9%E6%88%96N%E6%9C%88%E7%9A%84%E6%97%A5%E6%9C%9F--97049/#!/usr/bin/python'''Filename: "utildate.py"author:
Time of Update: 2018-12-05
python linux調試 python是動態語言,編譯器檢查不到運行時的文法問題,而這些低級問題常常造成調試效率很低。之前在linux伺服器上調試,都是通過print和異常報錯來排查,簡直弱爆了。python內建的pdb正是調試的利器。我們先建立一個測試指令碼:Shell代碼 touch debug.py 內容:Shell代碼 print "hello" i = 0 for j in range(10): i += j print i 常用命令說明:l
Time of Update: 2018-12-05
交換變數x =6y =5 x, y =y, x print x>>> 5print y>>> 6if 語句在行內print "Hello" if True else "World">>> Hello串連下面的最後一種方式在綁定兩個不同類型的對象時顯得很cool。fc =["Packers","49ers"]afc =["Ravens","Patriots"]print nfc + afc>>>
Time of Update: 2018-12-05
下面列出了一些在Python os模組中比較有用的部分。os.sep 可以取代作業系統特定的路徑分割符。os.name字串指示你正在使用的平台。比如對於Windows,它是'nt',而對於Linux/Unix使用者,它是'posix'。os.getcwd()函數得到當前工作目錄,即當前Python指令碼工作的目錄路徑。os.getenv()和os.putenv()函數分別用來讀取和設定環境變數。os.listdir()返回指定目錄下的所有檔案和目錄名。os.remove()函數用來刪除一個檔案。
Time of Update: 2018-12-05
文章目錄 內建函數屬性操作函數執行程式庫模組 內建函數str(string) 返回對象的字串表示list(seq)tuple(seq)int(x) 把字串或數字轉換為整數long(x)float(x)Complex(real, image)hex(i)oct(i)ord(c)
Time of Update: 2018-12-05
rope是一個python的重構庫。ropemacs是rope的emacs介面,ropemacs依賴於pymacs。pymacs是用來串連emacs和python的,有了它就可以在emacs中調用python了。要用ropemacs在emacs中進行python的補全,先要安裝pymacs(當然最先得確保python已經安裝上了),然後順序安裝rope, ropemacs。在.emacs中寫下下面代碼來設定pymacs:;;; Initialize Pymacs(autoload
Time of Update: 2018-12-05
代碼很簡單,所以就沒注釋了:}""" 採用windows事件和共用記憶體實現處理序間通訊。"""#readerimport win32event as w32eimport win32api as wapiimport mmapfile as mmfhEvent = w32e.CreateEvent(None , 0 , 0 , "Global\\JmdebuggerEvent")#system_info=wapi.GetSystemInfo()#page_size=system_info[1]
Time of Update: 2018-12-05
ElementTree(元素樹)。ElementTree是XML解析庫,已經在Python2.5之後被包括在標準庫中。ElementTree感覺就像一個輕量級的DOM,具有方便使用、十分友好的API。除了代碼可複用之外,它運行速度快,消耗記憶體較少。這裡我們重點推薦使用ElementTree。如果需要使用XML解析器,不妨先試一試ElementTree。2.5
Time of Update: 2018-12-05
Python的list,dictionary可以寫入file, 也可以從file中讀取。關於list:1)寫入檔案 self.existedBlog.write("your item data" + "\n")2)讀取 self.existedBlog = open("existedBlog", "r+") self.existedBlog.seek(0) currentBlogs = self.existedBlog.readlines(
Time of Update: 2018-12-05
http的資料需要2種編碼解碼。1. url中的特殊字元轉換, 比如”,‘, :,//等python3中通過urllib.parse.quote(..)和urllib.parse.unquote(..)來編碼解碼。如:import urllib.parseurl = "http://blog.csdn.net/muzizongheng"en = urllib.parse.quote(url)print(en)de = urllib.parse.unquote(en)print(de)en = "
Time of Update: 2018-12-05
演算法是比較低效的.僅僅是為了練習Python. #-*- coding:gb2312 -*-"""北大ACM 1001 exponentiation基本思路: 1.3099*12 去掉小數點後倒序得到[9,9,0,3,1] [9,9,3,0,1] * [9,9,0,3,1] = [9,9,0,3,1]*9*10^0 = [81, 81, 0,27, 9] + [9,9,0,3,1]*9*10^1 + [81
Time of Update: 2018-12-05
python實現雙色球機選功能import randomblue = [x for x in range (1,17)]red = [y for y in range (1,34)]print "The blue ball is :", random.choice(blue)for n in range(1,7): print "The %d red ball is :" %n, red.pop(random.randint(0, (len(red)-1)))>>> ==
Time of Update: 2018-12-05
#Python中開始那個Hello World挺簡單的。 #!user/bin/env python3 #這一行是shebang,用以指示用哪個解譯器來執行,如果有的話,必須在程式第一行 print("Hello World!") #Hello World! print(123, "123") #123 123 print(1 + 2) #3 route = 866 print(route, type(route)) #866 <class
Time of Update: 2018-12-05
某Python大牛如是說:“JetBrains出品。最好用的python IDE,很好很強大” 於是呼、偶便好奇心驅之、捲起她的頭蓋布、一探究竟 下面簡單介紹過程、後續提示等體驗後再獻上 ㈠ 簡單安裝: 這步很簡單、下載、然後到/bin下 ./pycharm.sh 即可 ㈡ 常見錯誤: ⑴ 錯誤一Unrecognized VM option
Time of Update: 2018-12-05
server.py: import socketsock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)sock.bind(("", 8080))sock.listen(5)try: while True: newSock,address = sock.accept() print "Connect from", address while True:
Time of Update: 2018-12-05
1.import recr = re.compile("怎麼寫呢") s = "abcd123d123ad1v123" print cr.findall(s) 我想找出以a開頭,以123字串結尾,但是中間不出現123這個字串的字串。 比如上題,結果應為:abcd123和ad1v123。2.import recr = re.compile("怎麼寫呢")s = "a123abvpd123d“p”f12ab123sabd123f1123abc"print
Time of Update: 2018-12-05
import HTMLParserclass MyParser(HTMLParser.HTMLParser): def __init__(self): HTMLParser.HTMLParser.__init__(self) def handle_starttag(self, tag, attrs): if tag == 'a': for name, value in attrs: if name ==
Time of Update: 2018-12-05
寫個python 指令碼實現檔案的遞迴拷貝減小字型增大字型作者:佚名 來源:本站整理 發布時間:2012-10-19 16:39:34今天翻電腦時突然發現有個存了很多照片和視頻的檔案夾,想起來是去年換手機(流行的小5)時拷出來的。看了幾張照片,往事又一幕幕的浮現在腦海,好吧,我是個感性的人。所以就想把這些照片翻著看一遍,可是拷出來的照片手機裡是按時間自動分檔案夾的,一個一個檔案夾拷很是麻煩,於是打算寫個python小指令碼來完成這個工作(扯這麼多,終於到主題了,囧)這是待拷貝的檔案夾根目錄,
Time of Update: 2018-12-05
Python 自動登入網站(處理Cookie) 部落格分類:Python Python代碼 def login(): cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) login_url = r'http://zhixing.bjtu.edu.cn/member.php?mod=logging&action=login&
Time of Update: 2018-12-05
auther:zfive5(zhaozidong)email :zfive5@yahoo.com.cndatetime: 2004-12-10 02:20:00本來現在睡了,但由於牙疼的厲害難以入睡,只好開啟機器寫點東西,那就邊學邊研究python下的com組件的使用!首先,用vc編寫一個簡單的com組件,VC IDL和類定義:#pragma once#include "resource.h" // 主符號// IIzfive5[ object, uuid("808D04AA-C8