A blog about one guys quest to learn Python, Django and Google App Engine.
Feed: http://appengineguy.com/atom.xml

fredag 1 augusti 2008

Encoding/unicode reminders to myself and others

Encoding is, along with Regular Expressions, one of those subjects I never seem to properly learn. Here are a few pointers to my future self whenever I run into a pesky UnicodeEncodeError.
  1. Read this article for the umtillionth time. This might be the time it "clicks" for you.
  2. Don't get fancy with ISO-8859-1. Just use UTF-8. App Engine hates everything that is UTF-8.
  3. Make sure your text editor saves the files using UTF-8 encoding.
  4. Make sure that the
  5. Put # coding=UTF-8 at the top of every .py file
  6. Put a u in front of every string that contains non-ascii chars. Like this u"Jag är en liten hatt och är bög"
  7. When handling incoming requests, make sure you set the encoding correctly using request.encoding = "UTF-8" in your view
  8. Use ugettext as your alias for _
  9. If a method (such as quote() or hashlib.sha224() requires bytestrings as input, encode your unicode strings first - like this: theunicodestring.encode("utf-8")

3 kommentarer:

Gurunath sa...

Hi dear....Check it out my wallpapers from india in gallery...read out others blog post ur comments...bye.

Bruno Patini Furtado sa...

This article clarifies a lot of textoencoding concepts: http://www.joelonsoftware.com/articles/Unicode.html

Anonym sa...

(法新社a倫敦二B十WE四日電) 「情色二零零七」情趣產品大產自二十三日起在倫敦的肯辛頓奧林匹亞展覽館舉成人電影行,倫敦成人電影人擺脫對性的保守態度踴躍參觀,許多穿皮衣與塑膠緊身衣的好色之徒擠進這項成人網站世界規模最大的成人生活展,估計三天展期可吸引八萬多好奇民眾參觀。色情

活動計畫負責人a片下載米里根承諾:「要搞浪漫、誘惑人、玩虐待,你渴望的我們都有。」
成人網站
他說:「時髦的設計成人影片與華麗女裝,從吊飾到束腹到真人大小的雕塑,是我們由a片今年展出的數千件產品精av選出的一部分,A片下載參展產品還包括時尚服飾、貼身女用內在美、鞋子、珠寶、玩具、影片、藝術av女優成人影片圖書及遊戲,更不要說性愛輔具及馬術裝備。」
色情
參觀民眾遊覽情色電影A片百五十多個攤位,有性感服AV裝、玩具a片及情色食品,迎合各種品味。

情色大舞台上表演的是美國野蠻搖滾歌手瑪莉蓮曼森的前妻─情色電影全世色情影片界頭牌脫衣舞孃黛塔范提思,這是她今年在英情色國唯一一場表演。

以一九四零年代風格演出的黛塔范提思表演性感的天堂鳥、旋轉木馬及羽扇等舞蹈AV女優

參展攤位有的推廣情趣用品,有的公開展示人體藝術和人體雕塑,也有情色藝術家工會成員提供建議。