Time of Update: 2015-04-22
標籤:CentOS 6.6內建的是Python 2.6.6,而編譯llvm需要Python 2.7以上。checking for python... /usr/bin/pythonchecking for python >= 2.7... not foundconfigure: error: found python 2.6.6 (/usr/bin/python); required >= 2.7yum中最新的也是Python 2.6.6,只能下載Python
Time of Update: 2015-04-20
標籤:python path 擴充 mingw 1.從官網下載對應版本的exe或者msi雙擊安裝。2.安裝setuptools,並且配置PATH環境變數 c:\Python\Scripts 後使用easy_install或者pip工具安裝並自動解決依賴關係。 例如 easy_install
Time of Update: 2015-04-18
標籤:python dict set dictPython內建了字典:dict的支援,dict全稱dictionary,在其他語言中也稱為map,使用鍵-值(key-value)儲存,具有極快的尋找速度。舉個例子,假設要根據同學的名字尋找對應的成績,如果用list實現,需要兩個list:names = [‘Michael‘, ‘Bob‘, ‘Tracy‘]scores = [95, 75, 85
Time of Update: 2015-04-17
標籤:backtracking python leetcode Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1
Time of Update: 2015-04-16
標籤:將文本轉換到NumPy 數組中,做機器學習或其他任何任務,文本處理的技能必不可少。python 實現實現了很精簡強大的文本處理功能:假設 檔案 traindata.csv 中有資料 1000行,3列特徵,第四列(最後一列)為類標籤1. 基本方法:def file2matrix(): dataMat = [] labelMat = [] fr = open(‘./traindata.csv‘,‘rb‘) fr.readline() for line in
Time of Update: 2015-04-16
標籤:pythonCounting SundaysProblem 19You are given the following information, but you may prefer to do some research for yourself.1 Jan 1900 was a Monday.Thirty days has September,April, June and November.All the rest have thirty-one,Saving February
Time of Update: 2015-04-16
標籤: 在使用python執行Ant構建時遇到的問題: 使用os.system()調用Ant構建時,不論構建成功還是失敗(BUILD SUCCESSFUL/BUILD FAILED),命令列的總是正常退出 要解決問題: 首先想到的是擷取ant命令的傳回值,根據傳回值來決定命令列的退出狀態(0或非0,0代表正常退出) 查閱相關資料,得知python調用系統命令的函數有:os.system、os.popen、commands.getstatusoutput/getstatus/getoutput、
Time of Update: 2015-04-15
標籤:本文適合有經驗的程式員儘快進入Python世界.特別地,如果你掌握Java和Javascript,不用1小時你就可以用Python快速流暢地寫有用的Python程式. 假設我們有這麼一項任務:簡單測試區域網路中的電腦是否連通.這些電腦的ip範圍從192.168.0.101到192.168.0.200.
Time of Update: 2015-04-13
標籤:接著上次的繼續。 簡單的畫圖函數 Pygame給我們提供了幾個簡單的畫圖函數,比如畫矩形,圓,橢圓,線,獨立的像素點。 下面這個程式就實現了一些簡單畫圖的操作 import pygame, sysfrom pygame.locals import *pygame.init()DISPLAYSURF = pygame.display.set_mode((500,400),0,32)BLACK = (0, 0 , 0)WHITE = (255, 255, 255)RED = (
Time of Update: 2015-04-14
標籤:除法相關保留小數 >>> from __future__ import division>>> 5/31.6666666666666667>>> 5/22.5 求商、求餘>>> divmod(5, 2)(2, 1)四捨五入>>>
Time of Update: 2015-04-09
標籤:operator.itemgetter函數operator模組提供的itemgetter函數用於擷取對象的哪些維的資料,參數為一些序號(即需要擷取的資料在對象中的序號),下面看例子。a = [1,2,3] >>> b=operator.itemgetter(1) //定義函數b,擷取對象的第1個域的值>>> b(a) 2 >>>
Time of Update: 2015-04-08
標籤:Python調用中科院NLPIR(ICTCLAS2015)詳解南京理工大學 電腦科學與工程學院 RuiXia_NUSTM課題組 ChaoLiu([email protected])-------------------------主要講解內容:1. NLPIR版本及下載2. 代碼問題3.
Time of Update: 2015-04-09
標籤:>>> help(print)Help on built-in function print in module builtins:print(...) print(value, ..., sep=‘ ‘, end=‘\n‘, file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword
Time of Update: 2015-04-03
標籤:簡介在軟體開發中經常要管理各種“串連”資源,通常我們會使用對應的串連池來管理,比如mysql資料庫連接可以用sqlalchemy中的池來管理,thrift串連可以通過thriftpool管理,redis-py中的StrictRedis實現本身就是基於串連池的,等等。
Time of Update: 2015-04-01
標籤:python 異常 文法 異常處理 語句 一個程式要保持穩定運行必須要有異常處理,本文將簡單介紹Python中的try…except..異常處理語句的使用。
Time of Update: 2015-03-30
標籤:# -*- coding: utf8 -*-‘‘‘__author__ = ‘[email protected]‘54: Spiral Matrixhttps://leetcode.com/problems/spiral-matrix/Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given
Time of Update: 2015-03-30
標籤: 我們常常需要下載網頁上很多喜歡的圖片,但是面對幾十甚至上百張的圖片,一個一個去另存新檔肯定是個很差的體驗。我們可以用urllib包擷取html的源碼,再以Regex把匹配的圖片連結放入一個list中,使用for迴圈來依次下載list中的連結。 import reimport urlliba = raw_input("Please input a URL: ")s = urllib.urlopen(a)s2 = s.read()def image(s2):
Time of Update: 2015-03-30
標籤:寫 Python 程式的時候,一邊寫模組一邊調試。調試是在 Python 自身的命令列終端進行的。但當對模組裡的代碼進行修改後,在原調試終端上執行到模組中新修改上去的內容。我之前是一直用退出再重新進入調試環境的方式,後面百度了下,找到了個更好的辦法,重新載入函數reload()可以重新載入模組的。比如:這樣就可以修改並重新載入,重新調試了。另外需要說明的是,如果有依賴的模組也修改了,記得先 reload() 依賴的模組,然後再 reload() 被調試的模組。python
Time of Update: 2015-03-30
標籤:string leetcode python Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C
Time of Update: 2015-03-30
標籤:add by zhj: 這個是豆瓣網友整理的PEP8,算是PEP8的一個簡易版本,因為原PEP8內容太多,所以建議先看這篇文章,然後再看PEP8中文翻譯 原文:http://www.douban.com/note/134971609/決定開始Python之路了,利用業餘時間,爭取更深入學習Python。程式設計語言不是藝術,而是工作或者說是工具,所以整理並遵循一套編碼規範是十分必要的。所以今天下午我根據PEP 8整理了一份,以後都照此編碼了,還會持續更新。PEP8 Python