Skip to main content

· One min read

把下面的 script copy 到 Ubiquity 的 command-editor 中。 每當看到不熟的生字,打開 Ubiquity,輸入「fy」,按下「Enter」鍵,即可連結到「Yahoo! 奇摩字典」看解釋。

> CmdUtils.CreateCommand({
> name: "fy",
> homepage: "zhpy.googlecode.com",
> author: { name: "Fred Lin", email: "[email protected]"},
> license: "MIT",
> description: "yahoo dict",
> help: "fy [keyword]",
>
> takes: {"keyword": noun_arb_text},
>
> preview: function( pblock, directObject ) {
> searchText = jQuery.trim(directObject.text)
> var previewTemplate = "輸入要搜尋的單字 ${query}";
> var previewData = {query: searchText};
> pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
> },
>
> execute: function( directObject ) {
> var url = "http://tw.dictionary.yahoo.com/dictionary?s={QUERY}"
> var urlString = url.replace("{QUERY}", directObject.text);
> Utils.openUrlInBrowser(urlString);
> }
> })

· 2 min read

Guido 在 Jaiku 上提到一篇「Learning Python」文章

裡面提到,Python 社群的最大問題就是注意力實在太分散了。相比用 PHP 或 Ruby 語言的人,問他們「對在哪方面使用該語言開發感興趣?」這問題,你幾乎都會聽到「Web 開發」。而在 Python 社群裡隨意抽五個人,問他們對在哪方面使用 Python 語言開發感興趣,則很可能會得到不同的五個答案。

所以在該文最後也提出了兩個問題:

1. 舉出 10 件所有人會想用 Python 語言寫而不用其他語言寫的事

2. 舉出 10 個所有人都會想問的關於 Python 語言的問題。

經過一些討論後,在此舉出「 10 件關於 Python 語言所有人都想問的問題」:

1. 為什麼 Python 既是動態語言又是強型別的語言? 2. 用哪個 IDE 寫 Python 比較好? 3. 有什麼關於 Python 語言的好書? 4. 學 python 語言能找到工作嗎? 5. 為什麼用縮排而不是用括弧或「End」來分段? 6. 用哪種 GUI 好? 7. 為什麼 Python 比 xxx 語言慢? 8. 如何開始學習 Python 語言?有什麼好建議嗎? 9. 有什麼小巧的 Python source 或專案項目可以參考練手? 10. 怎麼在 Windows 上直接跑 Python 程式 (不先安裝 Python)?

8/12/2008 更新: Guido 採用了這 10 個問題,並在 python wiki 上開了專頁

· 3 min read

你 / 妳是否是去死去死團的一員?在這個充滿閃光與柴可夫斯基 1812 序曲的節日,有種暫時失明的感覺?

為了對抗這個節日,我們就來自製閃光卡吧!

這個閃光卡製作的方法,就是寫個單詞記憶程式,並把這個單詞記憶程式命名為 閃光卡 (FlashCard) (* 註) XD

寫一個簡單的記憶程式不用花太多時間:我們只需要一個詞庫,與一個用作檢視與複習詞條的介面。

> #!/usr/bin/python
> # -*- coding: utf-8 -*-
>
> deck = [("a","apple"),
> ("b", "boy"),
> ("c", "cat"),
> ("d","dog")] #詞庫,包含4筆詞條
>
> import random
>
> help = "commands: Fail/Lucky/Quit" #支援的命令
>
> while True:
> card = random.choice(deck) # 從詞庫裡挑一個詞條,如 ('d', 'dog')
> which = random.choice(card) # 從詞條裡挑一個詞,如 ('d', 'dog') 中挑 'd' 或 'dog'
>
> print which #顯示詞
> print card[0], card[1] #印出完整答案
>
> action = raw_input("> ").lower() #輸入命令
> if action == "q": #按其他鍵繼續,按q就跳出迴圈
> break
> if "f" in action or "l" in action: #忘記時的處理策略
> print "...recorded."
> deck.append(card) #多加本詞條入詞庫中,以提升被選中的頻率
> if "h" in action:
> print help #印出說明
>

進一步修改參考:

  • 若要用作英文學習的話,不只前項 (英文)、後項 (中文解釋),也許還要一欄音標。

  • 詞庫應該要可以抽換

  • 詞庫應該要可以合併使用 (應該支援多詞庫)

  • 要用更有效的學習模式,如sm2

  • 應該可以用圖片代替文字,以做到支援「音標」等效果。參考資料

  • flashcard

  • Simple flashcard program in Python

* 註:英文中, flashcard 就是單詞記憶卡的意思。

· 3 min read

繼上一篇裡我們製作好閃光卡後,這裡再附送一個補充包: 平假名 / 片假名詞彙庫,讓閃光卡真正能運用於日常生活中 XD

> Hiragana = [("あ","a"), ("い", "i"), ("う", "u"), ("え","e"), ("お", "o"),
> ("か", "ka"), ("き", "ki"), ("く", "ku"), ("け", "ke"), ("こ", "ko"),
> ("さ", "sa"), ("し", "shi"), ("す", "shu"), ("せ", "se"), ("そ", "so"),
> ("た", "ta"), ("ち", "chi"), ("つ", "tsu"), ("て", "te"), ("と", "to"),
> ("な", "na"), ("に", "ni"), ("ぬ", "nu"), ("ね", "ne"), ("の", "no"),
> ("は", "ha"), ("ひ", "hi"), ("ふ", "hu"), ("へ", "he"), ("ほ", "ho"),
> ("ま", "ma"), ("み", "mi"), ("む", "mu"), ("め", "me"), ("も", "mo"),
> ("や", "ya"), ("ゆ", "yu"), ("よ", "yo"),
> ("ら", "ra"), ("り", "ri"), ("る", "ru"), ("れ", "re"), ("ろ", "ro"),
> ("わ", "wa"), ("ゐ", "wi"), ("ゑ", "we"), ("を", "wo"),
> ("が", "ga"), ("ぎ", "gi"), ("ぐ", "gu"), ("げ", "ge"), ("ご", "go"),
> ("ざ", "za"), ("じ", "ji"), ("ず", "zu"), ("ぜ", "ze"), ("ぞ", "zo"),
> ("だ", "da"), ("ぢ", "(ji)"), ("づ", "(zu)"), ("で", "de"), ("ど", "do"),
> ("ば", "ba"), ("び", "bi"), ("ぶ", "bu"), ("べ", "be"), ("ぼ", "bo"),
> ("ぱ", "pa"), ("ぴ", "pi"), ("ぷ", "pu"), ("ぺ", "pe"), ("ぽ", "po")
> ] #平假名詞庫
>
> Katakana = [("ア", "a"), ("イ", "i"), ("ウ", "u"), ("エ","e"), ("オ", "o"),
> ("カ", "ka"), ("キ", "ki"), ("ク", "ku"), ("ケ", "ke"), ("コ", "ko"),
> ("サ", "sa"), ("シ", "shi"), ("ス", "shu"), ("セ", "se"), ("ソ", "so"),
> ("タ", "ta"), ("チ", "chi"), ("ツ", "tsu"), ("テ", "te"), ("ト", "to"),
> ("ナ", "na"), ("ニ", "ni"), ("ヌ", "nu"), ("ネ", "ne"), ("ノ", "no"),
> ("ハ", "ha"), ("ヒ", "hi"), ("フ", "hu"), ("ヘ ", "he"), ("ホ", "ho"),
> ("マ", "ma"), ("ミ", "mi"), ("ム", "mu"), ("メ", "me"), ("モ", "mo"),
> ("ヤ", "ya"), ("ユ", "yu"), ("ヨ", "yo"),
> ("ラ", "ra"), ("リ", "ri"), ("ル", "ru"), ("レ", "re"), ("ロ", "ro"),
> ("ワ", "wa"), ("ヰ", "wi"), ("ヱ", "we"), ("ヲ", "wo"),
> ("ン", "n"),
> ("ガ", "ga"), ("ギ", "gi"), ("グ", "gu"), ("ゲ", "ge"), ("ゴ", "go"),
> ("ザ", "za"), ("ジ", "ji"), ("ズ", "zu"), ("ゼ", "ze"), ("ゾ", "zo"),
> ("ダ", "da"), ("ヂ", "(ji)"), ("ヅ", "(zu)"), ("デ", "de"), ("ド", "do"),
> ("バ", "ba"), ("ビ", "bi"), ("ブ", "bu"), ("ベ", "be"), ("ボ", "bo"),
> ("パ", "pa"), ("ピ", "pi"), ("プ", "pu"), ("ペ", "pe"), ("ポ", "po")
> ] #片假名詞庫
>
> deck = Hiragana

使用時,依照需求將 deck 改成等於 "Hiragana"、"Katakana",或 "Hiragana+Katakana" 即可。