bing的簡單英文字典工具,bing英文字典

來源:互聯網
上載者:User

bing的簡單英文字典工具,bing英文字典

今天看到園友心白水撰寫的《簡單翻譯工具--必應字典第三方API使用方法》,感覺很不錯,所以用Python也寫了一個。源碼如下:

 1 import urllib.request 2 import json 3  4 serviceurl='http://xtk.azurewebsites.net/BingDictService.aspx?Word=' 5  6 while True: 7     word = input('請輸入英文單詞: ') 8     if len(word) < 1 : 9         break10     url = serviceurl + word11     try:12         uh = urllib.request.urlopen(url)13     except:14         print('API錯誤,請重試')15         continue16     data = uh.read()17     try:18         js = json.loads(data.decode('utf-8'))19     except:20         js = ''21 22     if ( js["pronunciation"] == None):23         print("未查到匹配單詞")24 25     else:26         print("美音:[" ,js["pronunciation"]["AmE"], 
          "] 英音:[",js["pronunciation"]["BrE"],"]\n")27 for de in js["defs"]:28 print(de["pos"],de["def"])29 print("\n例句")30 for sam in js["sams"]:31 print("en:", sam["eng"])32 print("中文:", sam["chn"],"\n")33 continue

程式啟動並執行結果如下:

請輸入英文單詞: python
美音:[ 'paɪθɑn ] 英音:[ 'paɪθ(ə)n ]

n. 蟒;蚺蛇
Web 蟒蛇;巨蟒;派森

例句
en: Serpent blood spurted through the air, and in a minute, the huge python was dead.
中文: 蛇血在空中噴射出來,很快,大蟒蛇就死了。

en: Suggests that Python Web services implementations were not the only ones having trouble with the air fare quote service.
中文: 指出,PythonWeb服務實現並不是惟一使用機票報價服務有困難的。

en: Another idea is to require python owners to have their pets fitted with microchips.
中文: 另一個想法是讓養蛇人給他們的寵物配上微晶片。

en: A practice millennium python seeing, changes into an elegant young man, spits into the borneol in his mouth.
中文: 一修鍊千年的巨蟒看見,化為一翩翩少年,將冰片吐入他口中。

en: Participants reacted to the meaning threat implicit in Python by handing out a larger notional punishment to a lawbreaker.
中文: 參與者的反應是在巨蟒中一個具有隱含意義的威脅派由一個的更大名義讓處罰者進行處罰。

en: Quite a number of Python programmers have recommended Spark to me.
中文: 很多Python程式員都向我推薦Spark。

en: Zhu went out to investigate, and there, a few paces from his door, he saw a huge python!
中文: 祝出去查看,就在門口幾步遠的地方,他看到了一條巨蟒!

en: The balls disappeared, and the couple found a lumpy-looking carpet python nearby.
中文: 球不見了,夫婦卻發現在附近有一條身形凹凸不平的地毯蟒。

en: So, in a second study they used a description of a Monty Python sketch which participants weren't told was supposed to be a joke.
中文: 因此,在第二個實驗中,他們使用了一個描述巨蟒的素描,而參與者也沒有認為這應該是一個玩笑。

en: The scripts directory contains python scripts used to install and uninstall the application.
中文: 指令碼目錄包含用於安裝和卸載應用程式的python指令碼。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.