Time of Update: 2018-07-24
未設定資料格式前: import localenum = 123456789print(locale.format("%.2f", a, 1)) Output: 123456789.00 設定資料輸出格式: locale.setlocale(locale.LC_ALL, '') # Set the locale for your system Output: "Chinese
Time of Update: 2018-07-24
永遠不要刪除/usr/bin下系統預設的python!!!切記。 使用的是Ubuntu10.04 LTS版本,其中內建Python為2.6.5。前幾天一時手癢,把Python升級為了2.7.3。 # ./configure --prefix=/usr/local/python2.7# make# make install# cd /usr/bin# ln -sf /usr/local/bin/python python 一切順利哇,沒有任何問題哇。
Time of Update: 2018-07-24
1、關於pyaudio的使用,請參看前一篇博文: Python--pyAudio播放wav格式聲音: http://blog.csdn.net/xsc_c/article/details/8944077 2、關於wav檔案的操作,參看博文: Python--讀取wav格式檔案: http://blog.csdn.net/xsc_c/article/details/8941338 3、錄音的過程與播放使用的函數類似,可以參考使用手冊:
Time of Update: 2018-07-24
參考: 伯樂地址 用於索引操作,如字典。以上分別表示擷取、設定、刪除資料 #Python __doc__class C(object): """ Holy Shit What The Fuck """ def __init__(self): self.value = {} self.name = 'WuPeiQi' def __getitem__(self, item):
Time of Update: 2018-07-24
統計程式已耗用時間是time.clock() 裝飾器的參數 (*args, **kwargs) import timedef decorated_hello(func):def _hello(*args, **kwargs): print "<function name : " +func.__name__+">" print "<function call begin>" #start
Time of Update: 2018-07-24
學習yield之前,瞭解了迭代器, 產生器的概念。 沒有太多的細化。 迭代器對象: 支援iter和next()方法, 其中iter()方法返回迭代對象本身; next()方法返回容器的下一個元素, 在結尾時印發StopIteration異常。 產生器是迭代器,但是只能遍曆一次。 yield返回的就是產生器。 看執行個體, 銀行產生器。 # -*- coding: utf-8 -*-"""Created on Fri Dec 18 13:30:07
Time of Update: 2018-07-24
跟著部落格學了點python的知識 dict: 類與對象的所有成員; 類輸出的是全域的函數,變數等資訊。 對象輸出的只是對象擁有的普通變數而已 # http://python.jobbole.com/83747/class Province: country = 'China' def __init__(self, name, count): self.name = name self.count = count def
Time of Update: 2018-07-24
Below is my code , totally C type programmer, no excellent skills. import sys#time = input().strip()time = "00:05:45PM""""I don't know this issue.12:24:35AM -> 0:24:3512:24:35PM ->
Time of Update: 2018-07-24
慕課網 slots 由於Python是動態語言,任何執行個體在運行期都可以動態地添加屬性。 如果要限制添加的屬性,例如,Student類只允許添加 name、gender和score 這3個屬性,就可以利用Python的一個特殊的slots來實現。 class Person(object): __slots__ = ('name', 'gender') def __init__(self, name, gender): self.name = name
Time of Update: 2018-07-24
lambda運算式,這個鳥東西就是在一行語句中定義函數。 http://woodpecker.org.cn/diveintopython/power_of_introspection/lambda_functions.html >>> def f(x):... return x*2... >>> f(3)6>>> g = lambda x: x*2 >>>
Time of Update: 2018-07-24
Python -Xlib 關於Xlib,網上相關都介紹比較少,只能從庫檔案那裡擷取資訊啦 http://python-xlib.sourceforge.net/?page=home 基本概念就是:程式和X server建立串連,之後進行通訊,Event之類都是通過這個連結進行的。至於Pixmap, Graphic Context之類的,還需要進一步學習。 Sample: #!/usr/bin/env pyhon# message.py --example
Time of Update: 2018-07-24
socket.getaddrinfo(host, port, family=0, socktype=0, proto=0,
Time of Update: 2018-07-24
#理解#事物往往有多種狀態,對於每一種狀態,響應同一種輸入的反應不同,最典型的是有限狀態機器#與策略模式不同的是State模式關注的是狀態,將每一種狀態封裝,簡化複雜的switch或驅動表對狀態機器的維護#例子#我們知道水有三種狀態,冰,水,水汽,而且在加熱或冷卻的操作下會相互轉化class state: def heat(self,con): pass def cool(self,con): passclass water(state): def
Time of Update: 2018-07-24
說的寫總結,結果因為找實習,搬家拖了半個多月,不過也沒關係了,就是自己寫給自己看的,到以後想看的時候翻出來看一看,也算是一種懷念。
Time of Update: 2018-07-24
python 解析xml檔案出現錯誤:xml.parsers.expat.ExpatError: unknown encoding: line 1, column 30 這是由於編碼問題。 原因說明: shell環境的 LANG=zh_CN.UTF-8 執行一個程式,產生了一個XML檔案,在程式中將xml檔案的編碼設定成了GB2312,如“<?xml version="1.0"
Time of Update: 2018-07-24
轉自:http://linuxtoy.org/archives/9-free-python-books.html 上次筆者為大家介紹了 4 本免費的 Perl 語言編程書籍,今天我將向各位推薦 9 本免費的 Python 語言編程書籍,希望對你學習 Python 編程有所協助。 A Byte of Python by Swaroop C H 十分簡明的 Python 教程。“無論您剛接觸電腦還是一個有經驗的程式員,本書都將有助您學習使用 Python 語言。”包含
Time of Update: 2018-07-24
lists = [ 20 , 12 , 34 , 12 , 24 , 34 , 55 , 27 ]
Time of Update: 2018-07-24
請看這篇文章基本就能搞定了: PYTHON-進階-編碼處理小結 python中程式內部使用unicode編碼, tpye(s) 可以查看字串s的類型, 可能有兩種情況: 1 str , 2 unicode。 當定義字串 s = u"中國" 時, s 是 unicode 類型。 unicode類型可以使用s.encode('uft-8') 轉變成uft-8類型的str。 當定義字串 s = "中國"時, s
Time of Update: 2018-07-24
"""#slope one演算法是基於 ”同物品“ 之間的 ”評分差“ 的線性演算法,預測使用者對物品評分的個人化演算法#適用商品的更新不頻繁,數量相對穩定且物品數明顯小於使用者數的情境,依賴使用者的行為日誌和物品偏好的相關內容#優點:1演算法簡單,2可以發現使用者潛在的興趣愛好#缺點:依賴使用者行為,存在冷啟動問題和稀疏性問題"""#計算物品之間評分差的平均值,輸入如下#items 物品-使用者評分資料items#users
Time of Update: 2018-07-24
初學Python被編碼格式搞的很頭大,以下bug是遇到的編碼問題之一: 【BUG】UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15: ordinal not in range(128)或者UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128)