command-line translation gadget--python

Source: Internet
Author: User

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 'a translate module'4 ImportSYS5 ImportUrllib26 ImportJSON7 defTranslate (word):8Url="http://openapi.baidu.com/public/2.0/translate/dict/simple?client_id=F1jr7p2FxnbrO2AkqRubv0uW&q="+word+"&from=en&to=zh"#百度翻译的API9Response=urllib2.urlopen (URL)Tenresult=Response.read () OneDecode=json.loads (Result) AData="" -     ifdecode["errno"]==0: #解析API返回的Json数据 -result=decode['Data']['symbols'] the      forWlistinchResult: -        forMlistinchwlist['Parts']: -Data+=str (mlist[' Part'])+'\ n' -          forTlispinchmlist['means']: +data+=Tlisp -data+='\ n' +     Else: A     return "error!" at  -     PrintData - if __name__=='__main__': -Translate (sys.argv[1])

Indentation seems not very good, attached link

Git hub https://github.com/Hsiny/translater

Terminal directly run T "word" can be translated into Chinese

Other functions are added later,

UK-China

New Word Book

command-line translation gadget--python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.