Time of Update: 2015-04-28
標籤:記:最近在使用python進行學產生績管理系統設計時,遇到了一個中文顯示的問題,這個問題困擾了一個上午,查閱了有關資料,鎖定了原因——編碼問題。最終更改編碼設定,問題得到瞭解決。具體做法: 1 Python檔案設定編碼 utf-8 (檔案前面加上 #encoding=utf-8) 2 MySQL資料庫charset=utf-8 3 Python串連MySQL是加上參數
Time of Update: 2015-04-29
標籤:pythonpython將list連續元素和非連續元素分開轉換為指定字串貼吧網友提問http://tieba.baidu.com/p/3730249293已知一個由純數字(順序由小按大排序)元素組成的列表,比如li=[1,2,3,4,5,7,8,15,20,21,22,23,24,28]寫一個函數,讓它返回如下的字串str=‘1~5,7~8,15,20~24,28‘若數字連續,中間部分用 ~
Time of Update: 2015-04-28
標籤: Python開啟外部檔案有很多方法,os.popen開啟外部程式,但發現只能開啟檔案所在目錄的檔案os.system可開啟外部檔案os.system(command) command 要執行的命令,相當於在Windows的cmd視窗中輸入的命令。如果要向程式或者指令碼傳遞參數,可以使用空格分隔程式及多個參數。os.startfile (推薦)可開啟外部程式os.startfile (path [, operation])這樣執行的動作與在Windows
Time of Update: 2015-04-29
標籤:Python 檔案夾及檔案操作 我們經常會與檔案和目錄打交道,對於這些操作,python可以使用 os 及 shutill 模組,其中包含了很多操作檔案和目錄的函數。這邊,僅介紹通常會用到的方法。 os 可以操作簡單的檔案夾及檔案操作,引入用 import os,可用 help(os) 或是 dir(os) 查看其用法。注意有些函數在os模組中,有的是在os.path模組中。
Time of Update: 2015-04-27
標籤:1.列表切片>>> numbers = [1,2,3,5,6,7,8]>>> numbers[3]5>>> numbers[:3][1, 2, 3]>>> numbers[-3:][6, 7, 8]>>> numbers[:][1, 2, 3, 5, 6, 7,
Time of Update: 2015-04-27
標籤:range 函數說明:range([start,] stop[, step]),根據start與stop指定的範圍以及step設定的步長,產生一個序列。range樣本: >>> range(5) [0, 1, 2, 3, 4] >>> range(1,5) [1, 2,
Time of Update: 2015-04-28
標籤:http://edyfox.codecarver.org/html/boost_python.htmlBoost.Python 是 Boost 中的一個組件,使用它能夠大大簡化用 C++ 為 Python 寫擴充庫的步驟,提高開發效率,雖然目前它對 Python 嵌入 C++ 的支援還不是很多,但也能提供很大方便。另外,華宇煜也編寫了一份關於Boost.Python 簡明教程。1 Boost 安裝簡介在正式開始使用 Boost.Python
Time of Update: 2015-04-27
標籤:繼上一篇文章使用xlrd來讀Excel之後,這一篇文章就來介紹下,如何來寫Excel,寫Excel我們需要使用第三方庫xlwt,和xlrd一樣,xlrd表示read xls,xlwt表示write xls,同樣目前版本只支援97-03版本的Excel。 xlwt下載:xlwt 0.7.4安裝xlwt
Time of Update: 2015-04-27
標籤: 主要講的各個基本類型,integer,float,list,tuple,dic, list method:append,insert,extend, index tuple:no method ,can not change it,bu we can use the index to travel across dic: create a dic by using dic(), dic method:del d[key],d.clear
Time of Update: 2015-04-28
標籤:這篇文章主要介紹了python和shell變數互相傳遞方法,使用了環境變數、管道等方法 python -> shell:1.環境變數 複製代碼代碼如下:import os var=123或var=‘123‘os.environ[‘var‘]=str(var) #environ的索引值必須是字串 os.system(‘echo
Time of Update: 2015-04-26
標籤:milang python 本函數是返回一個靜態函數對象,主要用來作為靜態函數的修飾符。靜態函數的特性是可以直接通過類命名空間訪問,也就是說沒有定義類執行個體也可以使用此函數;也可以通過類執行個體來訪問。這跟JAVA或C++裡的靜態函數是一樣的作用。與classmethod是有區別,這點要注意。例子:#staticmethod()class Foo: @staticmethod def Add(a, b):
Time of Update: 2015-04-24
標籤:python要能夠使用import tab,最主要的是要有readline模組。預設python2.6雖然沒有裝tab模組,但是裝了readline模組的。如下:[[email protected] robin]# python2.6Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright",
Time of Update: 2015-04-26
標籤:python import import datetimeimport timestring轉datetimestr = ‘2012-11-19‘date_time =
Time of Update: 2015-04-24
標籤:RHEL6.4上升級python從2.6.6到2.7.3原始安裝好的redhat6.4上的python版本是2.6.6,不能滿足實際需要。升級的方法很多,從源碼升級或者從rpm包升級。其中從rpm包升級相對簡單。這裡記錄全部過程如下。準備新安裝的RHEL6.4,沒有安裝任何其他多餘的軟體,配置好ISO作為本地YUM源。看看升級過程如下:1 升級python1) 首先是下載python的RPM包共4個:wget -c --no-check-certificate http://li.nux.
Time of Update: 2015-04-25
標籤:python建立xml執行個體 模仿下面的xml檔案,使用python指令碼進行建立。<?xml version=‘1.0‘?><database> <user username="user" fromAddress="[email protected]" fullName="John Q. User" password="pass"> <subscription
Time of Update: 2015-04-26
標籤: Python引入subprocess模組來管理子進程,以取代一些舊模組的方法:如 os.system、os.spawn*、os.popen*、popen2.*、commands.*不但可以調用外部的命令作為子進程,而且可以串連到子進程的input/output/error管道,擷取相關的返回資訊。 subprocess模組中只定義了一個類:
Time of Update: 2015-04-25
標籤:一、JSON是什嗎? JSON是一種輕量級的資料交換格式 二、Python處理JSON的思維 其實很容易理解,無非是將資料編成JSON格式資料和吧JSON格式的資料解析出來 三、Python處理JSON的具體方法 1、json.dumps()
Time of Update: 2015-04-24
標籤:python欄位是Python是字典中唯一的鍵-值類型,是Python中非常重要的資料結構,因其用雜湊的方式儲存資料,其複雜度為O(1),速度非常快。下面列出字典的常用的用途.【字典中常見方法列表】#方法
Time of Update: 2015-04-24
標籤:原題:You are given two linked lists representing two non-negative numbers.The digits are stored in reverse order and each of their nodes contain a single digitAdd the two numbers and return it as a linked listInput: (2->4->3) + (5->6->4)
Time of Update: 2015-04-24
標籤:with open as 最近用到python來處理文字檔了,然後需要處理檔案。發現python中提供的with open as 這個還是用的不錯的!好的,廢話不多說了,看下例子:with open(‘./sigir_title_cizu.txt‘) as cizu, open(‘sigir_title.txt‘) as titles:cizuData =