Not much to say, on the code:
1 #!/usr/bin/python2 #-*-encoding=utf-8-*-3 4 ImportUrllib5 ImportUrllib26 ImportJSON7 8Keys=raw_input ('input you word >')9 Tenargs={'Q': Keys,' from':'en',' to':'ZH'} One Aencode_args=Urllib.urlencode (args) - -Url='http://openapi.baidu.com/public/2.0/translate/dict/simple?client_id= here to add your api-key&'+Encode_args the PrintURL - -Json_encode=urllib2.urlopen (URL). Read () -Json_decode=json.loads (Json_encode) + -symbols=json_decode['Data']['symbols'] + A Print 'The key words you enter are:', json_decode['Data']['Word_name']#Output Search Keywords at - forIndexinchSymbols#each symbols is parsed - forEveryinchindex['Parts']:#parts parsing of each part - Print 'Part of speech:', every[' Part'] - Print 'Interpretation:' - forIinchevery['means']:#to parse the meaning of each part in Print '|-', I - Print 'American Sound', index['Ph_am'] to Print 'English Tone', index['ph_en']
Chinese query is not supported for the time being, because no Chinese input is found.
Above.
Python command-line dictionary built using Baidu translation open API