Time of Update: 2018-12-04
Using functions and exception pattern dictionaries to simplify error recovery. One of the features that makes Python a great programming language is exceptions for error handling. Exceptions are convenient in many ways for handling errors and
Time of Update: 2018-12-04
在遊戲中,我要監控記錄物品系統中的背包變動情況。假設背包的儲存結構是這樣的。是一個字典,{物品id:數量}。在背包類初始化的時候,把背包物品資訊copy儲存到一個oldbag變數,進行一些物品操作後(比如使用物品,領取物品獎勵等),在調用save()方法存進redis時,對新的bag字典與oldbag字典進行差異對比就得出變動情況了。千言不如一碼。def symmetric_difference(_oldobj,_newobj): _oldkeys = _oldobj.keys()
Time of Update: 2018-12-03
uuid是一種唯一標識,在許多領域作為標識用途。python的uuid模組就是用來產生它的。閑話不說,python提供的產生uuid的方法一共有4種,分別是:1.從硬體地址和時間產生2.從md5演算法產生3.隨機產生4.從SHA-1演算法產生他們在uuid模組裡對應uuid1, uuid3, uuid4, uuid5這幾個方法,注意沒有uuid2。下面是樣本:
Time of Update: 2018-12-04
測試環境1:win7測試環境2:ubuntu10.04 安裝Erlang環境1、下載: http://erlang.org/download.html 自己根據需要下載源碼包或win的二進位包2、安裝:windows環境就沒啥好說的了,一路next~主要說下linux環境,其實我用的ubuntu10.04已經預裝了erlang,版本是RB13B03,但是貌似不支援最新版的RabbitMQ對於想使用最新版RabbitMQ或還沒有安裝erlang環境的童鞋,需要重新安裝下最新版的erlang目前Er
Time of Update: 2018-12-04
日誌的使用:1、 日誌的標準模組logging基本可以滿足我的工作。2、 設定log的初始化工作:logging.basicConfig( filename = "test.log", format = "[%(asctime)s-%(levelname)s] %(message)s[%(filename)s,%(lineno)d]", level = logging.INFO, datefmt = "%F %T")3、
Time of Update: 2018-12-04
近期在研究libvirt,儲存建立iscsi儲存池import libvirtconn=libvirt.open('qemu:///system')#conn=libvirt.open('qemu:///system') /dev/disk/by-pathxmldesc='''<pool type='iscsi'> <name>iscsi</name> <source> <host name="192.168.x.x"/>
Time of Update: 2018-12-04
Python常用類型>>> a = 1>>> type(a)<class 'int'>>>> a = 1.0>>> type(a)<class 'float'>>>> a = 'abcd'>>> type(a)<class 'str'>>>> a = (1,2)>>> type(a)<class 'tuple'&
Time of Update: 2018-12-03
因為公司內部的介面返回的字串支援2種形式:php數組,xml;結果php數組python不能直接用,而xml字串的格式不是標準的,所以也不能用標準模組解析。【不標準的地方是某些節點會的名稱是以數字開頭的】,所以寫個簡單的腳步來解析一下檔案,用來做介面測試。#!/usr/bin/env python #encoding: utf-8import reclass xmlparse: def __init__(self, xmlstr): self.xmlstr =
Time of Update: 2018-12-03
#!\urs\bin\env python#encoding:utf-8 #設定編碼方式 import osimport reclass loop_file: def __init__(self, root_dir, short_exclude=[], long_exclude=[], file_extend=[]): self.root_dir = root_dir self.short_exclude = short_exclude
Time of Update: 2018-12-03
計算映像相似性——《Python也可以》之一 聲明:本文最初發表於賴勇浩(戀花蝶)的部落格http://blog.csdn.net/lanphaday,如蒙轉載,敬請確保全文完整,未經同意,不得用於商業用途。 關於《Python也可以》系列:這是我打算把這幾年裡做的一些實驗和代碼寫出來,涉及的面比較廣,也比較雜,可能會有影像處理、檢索等方面的內容,也會有中文分詞、文本分類、拼音、錯誤修正等內容。毫不掩飾地說:在部落格發這系列文章的原因在於宣傳 python
Time of Update: 2018-12-03
賴勇浩(http://laiyonghao.com)前段時間,我發過一篇文章(見:http://blog.csdn.net/lanphaday/archive/2010/11/29/6043605.aspx),講了幾個我希望能夠在 Python 看到的幾個特性,其中第三個 message-oriented programming
Time of Update: 2018-12-03
今天終於可以用wxPython開發GUI程式了,非常高興。把其中的一些注意點寫下來以供參考。在windows XP平台下,首先需要做以下環境的配置: 1. 首先是安裝python ,安裝完之後將python/bin所在目錄添加到path中。 2. 安裝wxPython, 此時要注意wxPython的版本要與前面python的版本一致。 3. 安裝py2exe,
Time of Update: 2018-12-03
最近發現了一個比較有用的自動工具庫:
Time of Update: 2018-12-03
今天在某論壇中看到應用Python對中文進行分句的源碼(http://www.corpus4u.org/forum/showthread.php?s=86a8e08ccda003206c8f8d66c011df67&t=8662&page=2),原理很簡單,帖上來傳播一下。注釋是我自己加上去的。向原作者致謝!# coding: utf-8 #設定分句的標誌符號;可以根據實際需要進行修改cutlist ="。!?".decode('utf-8')#檢查某字元是否分句標誌符號的函數;
Time of Update: 2018-12-03
使用chartdir來組建圖表真的是太方便了!!可以用與web中產生圖片,也可以作為單獨的應用程式產生各類統計圖,非常實用,也非常的好用,還跨平台。美中不足的是圖片中使用中文的時候有些問題,因為使用了PIL來產生圖片,偏偏PIL對中文的支援不夠。。。它的官方網站是 http://www.advsofteng.com/download.html它同時也提供 ChartDirector for ASP/COM/VB ChartDirector for
Time of Update: 2018-12-04
發現python具有類似Hadoop中的Map-reduce概念的標準函數,於是變搞來玩玩,發現還是蠻好玩的,雖然功能簡陋了點,不過該做的都做了。map(func, *iterables) --> map object Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortest iterable is
Time of Update: 2018-12-04
1.#fout.py python中對於計時器的調用....顯示...from dummy_threading import *class Fout: "This class contain some functions to display..." _defualt_string="wait...system is waiting... ..." _arg=["start...","...end"] def out(self, i=0,
Time of Update: 2018-12-04
python 定時器在啟動並執行時候有不少的問題需要我們注意,下面我們就來看看在運行效果上的問題如何解決。希望大家有所收穫。運行效果如上, 代碼如下: #!/usr/bin/env python import datetime import sys import threading from tkinter import * minute = 60 * int(sys.argv[1]) Curtime = datetime.datetime.now() print ("時間為:",
Time of Update: 2018-12-04
前段時間使用了一下google的部落格空間,感覺也很一般,所以現在把那裡的幾篇文章轉過來。執行python指令碼只需要對python檔案做如下操作即可:在python檔案裡第一行加上#! /usr/bin/python,即你的python解譯器所在的目錄。另外還有一種寫法是#! /usr/bin/env python編輯完成python指令檔後為它加上可執行許可權。例如你的python指令檔叫做runit.py,那麼就在shell中輸入如下命令:chmod +x
Time of Update: 2018-12-04
文章目錄 [Python Tips]去除 Trivial 指派陳述式 [Python Tips]去除 Trivial 指派陳述式寫 python 這麼久,其實有許多小技巧記在了腦子裡,當然,其中也爛掉了不少。今天正好有同事問關於怎麼去除 trivial 指派陳述式問題,覺得應當以此為契機,養成把這些小技巧記錄下來發表到部落格上的習慣,一來不會久了之後技巧爛在了腦子裡,二來也許能對別人有所裨益呢?trivial 指派陳述式的問題在於許多