英単語リストにある単語を発音して、同時に辞書.appで参照するスクリプト
ちなみに辞書.appを前面に表示しないようにした
(環境:MacOSX10.6, python2.6)
コマンドの使い方はここを参照した
コード
#!/usr/bin/env python # *-# -*- coding: utf-8 -*- import os def conv_replase_str(word): # rep_list = ["'", "~","(",")"," "] rep_list = ["'"," "] for rep in rep_list: word = word.replace(rep, "\\" + rep) return word def say(look_up_a_word): os.system("say %s" % look_up_a_word) def look_at_a_dictionary(look_up_a_word): os.system("open -g dict://%s" % look_up_a_word) def say_and_look_at_a_dictionary(look_up_a_word): look_up_a_word = conv_replase_str(look_up_a_word) say(look_up_a_word) look_at_a_dictionary(look_up_a_word) if __name__ == '__main__': example = [ "Everybody", "business", "is", "nobody's", "business", ] for word in example: say_and_look_at_a_dictionary(word) print word
結果
単語の中に『'』があると辞書.appで表示されない。『\'』にしても。
なんでかな?
解決
>>> import urllib >>> print urllib.quote("'") %27 >>> look_at_a_dictionary("/I don%27t feel like a walk.")