2010年7月22日 星期四

Python的UUID產出辦法

python的uuid模組有四種方式可以產生uuid

  1. 使用硬體及時間
  2. 以MD5對字串取值
  3. 隨機產生
  4. 使用SHA-1


以上分別對應的方式為:


#-*- encoding: utf-8 -*-
import uuid

print uuid.uuid1()
print uuid.uuid3(uuid.NAMESPACE_DNS, 'testname')
print uuid.uuid4()
print uuid.uuid5(uuid.NAMESPACE_DNS, 'testme')

2010年7月17日 星期六

在寫GAE時,如果上傳檔案出現錯誤

TypeError: Blob() argument should be str instance, not unicode

可參考
http://code.google.com/p/googleappengine/issues/detail?id=1784

其中提到

要將From送出的資料改成
enctype="multipart/form-data"(多部分表單張貼)
 
格式才會正常,不然圖片會以UTF8送,發生錯誤。

2010年4月29日 星期四

Python標準輸入的使用方法

import sys
data = sys.stdin.readlines()
print "Counted", len(data), "lines."
 
 
要匯入sys物件,可以開始使用