Time of Update: 2015-04-03
標籤:字典有一個很好用的方法,就是get,既可以預防KeyError異常,也可以為不存在的key設定一個預設的value例如:v=d.get(‘k‘,‘default‘)而列表沒有一個類似的方法,如果訪問的下標超出列表的長度,就會跳出異常如果想在列表中實現字典的get方法的功能,可以這樣:l = [0, 1]d = dict(enumerate(l))print d.get(3, 3)就是把一個列錶轉換成字典,然後用get訪問Python 列表實現字典的get功能
Time of Update: 2015-04-04
標籤:熟悉python語言, 以及學會python的編碼方式. 熟悉python庫, 遇到開發工作單位的時候知道如何去找對應的模組. 知道如何尋找和擷取第三方的python庫, 以應付開發工作單位. 學習步驟安裝開發環境如果你在window下, 去下載pythonxy安裝起來, 然後運行python, 進入python解釋環境.如果你在ubuntu下, 執行: sudo apt-get install python, 然後在命令列下運行python,
Time of Update: 2015-04-03
標籤:test1.py中,當分母為0的時候,調用系統退出#!/usr/bin/pythonimport sysdef division(a=1, b=1): if b==0: print ‘b eq 0‘ sys.exit(1) else: return a/btest2.py中,用try..except捕獲異常,然後traceback.print_exc()列印。#!/usr/bin/pythonimport sysimport
Time of Update: 2015-04-03
標籤:解決方案 python 開發 伺服器 背景介紹pyqt 用戶端方案C 和python 混合編程方案純python伺服器解決方案由於對伺服器開發熟悉程度不高暫時未想到應用程式伺服器的開發應用求指點網路快速測試方案學術研究技術規劃反思問題背景介紹 三年的C++ windows 用戶端的開發經驗, 接觸python也快有兩年了。
Time of Update: 2015-04-01
標籤:python中對檔案、檔案夾(檔案操作函數)的操作需要涉及到os模組和shutil模組。得到當前工作目錄,即當前Python指令碼工作的目錄路徑: os.getcwd()返回指定目錄下的所有檔案和目錄名:os.listdir()函數用來刪除一個檔案:os.remove()刪除多個目錄:os.removedirs(r“c:\python”)檢驗給出的路徑是否是一個檔案:os.path.isfile()檢驗給出的路徑是否是一個目錄:os.path.isdir(
Time of Update: 2015-04-01
標籤:#coding:utf-8import os;def SortList(item): return item[1];def ReadSize(fileName): return float(os.path.getsize(fileName));def WriteAll(path): l = [] loger =
Time of Update: 2015-04-01
標籤:#設a為字串import timea = "2011-09-28 10:00:00"#中間過程,一般都需要將字串轉化為時間數組time.strptime(a,‘%Y-%m-%d %H:%M:%S‘)>>time.struct_time(tm_year=2011, tm_mon=9, tm_mday=27, tm_hour=10, tm_min=50, tm_sec=0, tm_wday=1, tm_yday=270, tm_isdst=-1)#將"2011-09-28 10:0
Time of Update: 2015-04-01
標籤:Python 3.3.5Debian 3.12One thing I found weird is using the following code is that the input I entered isn‘t displayed, even after I terminate the script. However I found a way accidently which is to set stdin as DEVNULL.1 try:2 stdout =
Time of Update: 2015-04-02
標籤:make sure your python version > Python 2.3 1 從一個小案例說起: cat howto_logging.py #coding=utf8# file name: howto_logging# this file shows how to use logging# made by vasks, email:[email protected]import logging# 建立一個logger,層級:DEBUGlogger =
Time of Update: 2015-04-02
標籤:python __new__ 先看下object類中對__new__()方法的定義:class object: @staticmethod # known case of __new__ def __new__(cls, *more): # known special case of object.__new__ """ T.__new__(S, ...) ->
Time of Update: 2015-04-02
標籤: 露珠是一名愛好養花的測試員,熟悉python,減少了很多重複性的工作。扯一扯這兩個月的學習總結:基礎 文法,資料結構什麼的翻一遍手冊足夠了,用到的時候不會了再查,相信只有你想不到的沒有python不支援的(此處忽略老牛)。檔案 嘛,作為一名測試,起初最需要用到的就是python的檔案操作,各種讀寫檔案,分析資料神馬的。。這裡需要用到的就是python file操作、以及各種資料結構的用法了,比如List,dict
Time of Update: 2015-04-02
標籤:python pydev django helloworld 作業系統:windows開發環境:Eclipse + PyDev1.
Time of Update: 2015-03-31
標籤:爬蟲 多線程 python爬蟲 regex python爬蟲Pragmatic系列IV說明:在上一篇部落格中,我們已經做到了從趕集網上單個首頁中抓取所有的連結,並下載下來,分析後存入Excel中。本次目標:在本節中,我們將使用python多線程技術從趕集網上抓取連結並分析,注意,我們這次能夠抓獲的連結數目可以遠遠大於上一篇部落格中抓獲的。分析:用爬蟲統計資
Time of Update: 2015-03-30
標籤:python pyc 由於python程式的py檔案很容易泄露原始碼,所以python可以編譯成保密的pyc檔案。python的pyc檔案是一種二進位檔案,py檔案變成pyc檔案後,載入的速度有所提高,而且pyc是一種跨平台的位元組碼,是由python的虛擬機器來執行的,這個是類似於JAVA或者.NET的虛擬機器的概念。編譯py檔案到pyc檔案的方法:在命令列輸入:python -m
Time of Update: 2015-03-31
標籤:password change python 使用者 import #!/usr/bin/pythonfrom fabric.api import *for i in range(24,34): host = ‘[email protected]‘ + str(i)
Time of Update: 2015-04-01
標籤:greenev是一個基於greenlet協程,事件驅動,非阻塞socket模型的Python網路服務架構,它使得可以編寫同步的代碼,卻得到非同步執行的優點。 本項目受到gevent, openresty, alilua, skynet, clowwindy/ssloop的啟發,在此表示感謝。 reactor模式採用基於epoll, kqueue, poll, select的IO複用機制基於底層的reactor完成上層greenlet協程的調度在CentOS6.5,
Time of Update: 2015-03-31
標籤:python+editplus文法高亮和自動補全:http://www.editplus.com/files/pythonfiles.zip選擇功能表列的-->工具-->配置使用者工具-->設定&文法檔案名稱擴充:py文法檔案:python_extd.stx自動完成:python.acp配置解釋程式:開啟editplus選擇工具-->配置使用者工具,點擊組名建立一個python組,緊接著點擊添加工具選擇-->應用程式在菜單文字:python命令:選擇你
Time of Update: 2015-03-30
標籤:(掌握os模組,你需要瞭解Linux或類Unix系統下常用命令的操作) os.name 指示你正在使用的平台。比如對於Windows,它是‘nt‘,而對於Linux/Unix使用者,它是‘posix‘。os.getcwd() 得到當前工作目錄,即當前Python指令碼工作的目錄路徑。os.mkdir( ‘path‘ ) 建立新目錄,path為一個字串,表示新目錄的路徑。os.rmdir(
Time of Update: 2015-03-30
標籤:WvsScannerQueue.pyVersion: Python 2.7.*Acunetix Web Vulnerability Scanner 輔助Python指令碼的第一個版本。功能:掃描URL.TXT檔案中所有URL掃描完成一個URL後立即過濾報告,並且提權漏洞標題發送給自己存在的問題:掃描一些網站很慢畢竟這個就是調用Acunetix Web Vulnerability Scanner
Time of Update: 2015-03-30
標籤:轉自:http://www.tuicool.com/articles/VfQfM3 1. 下載protobuf原始碼(當前最新版本為:2.5.0) #cd /opt #wget https://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz2. 解壓,編譯,安裝 #tar zxvf protobuf-2.5.0.tar.gz #cd