Time of Update: 2015-06-20
標籤:python pdbPYTHON 代碼,尤其是別人寫的代碼看不懂。怎麼辦? 其實PYTHON中也提供了類似於C語言中用於debug 的 gdb。它叫做pdb。結合本人自己的學習,進行簡單的舉例,以做備忘和補償學習。首先參考資料:1、http://web.stanford.edu/class/physics91si/2013/handouts/Pdb_Commands.pdf2、https://docs.python.org/2/library/pdb.html以 shadowsocks
Time of Update: 2015-06-20
標籤:#coding:utf-8import urllib#######爬蟲v0.1 利用urlib2 和 字串內建函數####### 擷取網頁內容def getHtml(url): page = urllib.urlopen(url) html = page.read() return htmldef content(html): # 內容分割的標籤 str = ‘<article class="article-content">‘
Time of Update: 2015-06-21
標籤:python# -*- coding: utf-8 -*-__author__ = 'xy'#切片(slice)的擴充使用方法#1 用步長索引來進行擴充的切片操作# slice[1:2:3]其中第3個位置表示步長,預設為1#簡單的str翻轉:s = 'abcde'print s[::-1]# >>>'edcba'#間隔一個字元取值:print s[::2]# >>>'ace'#2
Time of Update: 2015-06-21
標籤:python linux world 程式 下載安裝 Linux環境- 大多Linux發行版均預設安裝了Python環境。- 輸入Python可啟動Python互動模式- 程式編輯精選使用VIMWindows環境- 可下載安裝Python的msi包直接安裝- 內建Python的GUI開發環境-
Time of Update: 2015-06-20
標籤:python 留言薄 第 0023 題: 使用 Python 的 Web 架構,做一個 Web 版本 留言簿 應用。閱讀資料:Python 有哪些 Web 架構思路:Flask是一個使用 Python 編寫的輕量級 Web 應用程式架構。
Time of Update: 2015-06-21
標籤:python 最佳化 對象 # -*- coding: utf-8 -*-## def displayNumType(num):# print num, 'is',# if type(num) == type(0):# print 'an integer'# elif type(num) == type(0L):#
Time of Update: 2015-06-20
標籤:一、常用方法findall:匹配所有符合規律的內容,返回包含結果的列表search:匹配並提取第一個符合規律的內容,返回一個Regex對象(Object)sub:替換符合規律的內容,返回替換後的值。S:表示多行匹配注意:findall與search的區別:findall會遍曆整個載入範圍裡的內容,並逐一返回匹配到的內容;而search一旦匹配到指定內容就不再往下匹配,返回結果,搜尋結束。二、常用符號:.號:匹配任一字元,分行符號\n除外>>> import re>&
Time of Update: 2015-06-22
標籤:python 代碼規範 Python官方文檔: https://www.python.org/dev/peps/pep-0008/代碼風格:使用4個空格來表示縮排,最好不使用tab,更勿將兩者混用函數間換行至少一行類之間換行至少兩行字典,列表,元祖中元素應該在逗號前添加一個空格字典中鍵後面的冒號:應在值與冒號:之間添加空格,而不是:與鍵之前間.
Time of Update: 2015-06-20
標籤:python 解譯器 原文地址:Making a simple VM interpreter in Python更新:根據大家的評論我對代碼做了輕微的改動。感謝 robin-gvx、 bs4h 和 Dagur,具體代碼見這裡Stack Machine 本身並沒有任何的寄存器,它將所需要處理的值全部放入堆棧中而後進行處理。Stack Machine 雖然簡單但是卻十分強大,這也是為神馬
Time of Update: 2015-06-20
標籤:pythonPython RESTful API 開發 需要下載:flaskrequests :http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
Time of Update: 2015-06-19
標籤:#encoding=utf-8 print ‘中國‘ #字典的一鍵多值 print‘方案一 list作為dict的值 值允許重複‘ d1={} key=1 value=2 d1.setdefault(key,[]).append(value) value=2 d1.setdefault(key,[]).append(value) print d1 #擷取值 print ‘方案一 擷取值‘ print list(d1[key])
Time of Update: 2015-06-17
標籤:libxml/xmlversion.h: No such file or directorysudo apt-get install libxml2-dev libxslt1-devEnvironmentError: mysql_config not foundsudo apt-get install libmysqlclient-devnumpy.distutils.system_info.NotFoundError: no lapack/blas resources
Time of Update: 2015-06-16
標籤:python cat 檔案操作 類比linux的cat命令,列印從命令列輸入的檔案名稱#!/usr/bin/python#Filename:cat.pyhelpString = '''This program prints files to the standard output.Any number of files can be
Time of Update: 2015-06-15
標籤:centos原生python為2.6.6,可以通過下面的命令查看#python -VPython 2.6.6 1、下載你需要的python版本到https://www.python.org/downloads/官網下載需要的版本,目前linux使用的版本是.tgz或.tar.xz版本。2、解壓下載檔案以tar.xz為例#xz -d Python-2.7.8.tar.xz#tar -xvf
Time of Update: 2015-06-12
標籤:原文:http://blog.csdn.net/liyzh_inspur/article/details/6294292 import urllibimport urllib2url = ‘http://umbra.nascom.nasa.gov/cgi-bin/eit-catalog.cgi‘values = {‘obs_year‘:‘2011‘,‘obs_month‘:‘March‘,
Time of Update: 2015-06-14
標籤:milang python 本函數是實現返回對象object的屬性和屬性值的字典對象。如果預設不輸入參數,就列印當前調用位置的屬性和屬性值,相當於locals()的功能。如果有參數輸入,就只列印這個參數相應的屬性和屬性值。例子:#vars()print(vars())class Foo: a = 1print(vars(Foo))foo =
Time of Update: 2015-06-14
標籤:Largest NumberGiven a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be very large, so you need to
Time of Update: 2015-06-11
標籤:python 標準 json 格式化 format 這段時間做的事情比較雜亂,一部分時間在做營運,一部分時間在做開發,總是太著急,總是感覺很多東西做的不是很滿意。還是要靜下心來好好想一想,多花些時間來改進,重構和思考。 軟體開發絕不緊緊是寫代碼,完成功能那麼簡單的事情
Time of Update: 2015-06-09
標籤:python模組的使用:通過import匯入模組,然後按照“模組.函數”的格式使用模組的函數。 如:>>> import math>>> math.floor(32.9)如果不希望每次調用函數的時候都寫上模組的名字,可以使用import另外一種形式。 例:>>> from math import sqrt>>> sqrt(9)使用了”from 模組 import 函數“之後,可以直接使用函數,不需要模組名做首碼。
Time of Update: 2015-06-11
標籤:在Python中,round函數對小數進行四捨五入的截斷。然而:>>> round(3.55, 1)3.5官方文檔對於函數的解釋是:Unfortunately, most decimal fractions cannot be represented exactly as binary fractions. A consequence is that, in general, the decimal floating-point numbers you enter