Simple Python Dictionary :)
摘自 http://github.com/panweizeng/home/blob/master/code/python/dict/dict.py 支持简单的Ch to En 和En to Ch我把它放在 /usr/bin/dict 1234567891011
$ dict 白痴
单词:白痴 音标: bái chī 释义:idiot idiocy 例句:他很聪明,但有时举止像是白痴。 翻译:He is intelligent, but sometimes he behaves like an idiot. 例句:我不讳言,我说过他是白痴。 翻译:I didn't mince matters: I said he was an idiot. 例句:真是白痴一个! 翻译:What a stupid idiot!
#!/usr/bin/python
#coding=utf8
import urllib
import sys
import os
import re
import xml.dom.minidom as xml#API_URL = 'http://dict.cn/ws.php?utf8=true&q=%s'
API_URL = 'http://dict-co.iciba.com/api/dictionary.php?w=%s'
def getword(word):xmls = urllib.urlopen(API_URL%urllib.quote(word)).read()#print xmlsroot = xml.parseString(xmls).documentElement#print re.sub(u'>', '>\n',xmls)#tags = {'key':'单词', 'pron':'音标', 'def':'释义', 'sent':'例句', 'orig':'例句', 'trans':'翻译', 'acceptation':'释义'}tags = {'key':'单词', 'ps':'音标', 'def':'释义', 'sent':'例句', 'orig':'例句', 'trans':'翻译', 'acceptation':'释义'}def isElement(node):return node.nodeType == node.ELEMENT_NODEdef isText(node):return node.nodeType == node.TEXT_NODEdef show(node, tagName=None):if isText(node):tag = tags.get(tagName, tagName)print '%s:%s'%(tag, node.nodeValue)elif isElement(node) and tags.has_key(node.tagName):[show(i, node.tagName) for i in node.childNodes][ show(i) for i in root.childNodes if isElement(i) ]def main():if len(sys.argv) >= 2:word = ' '.join(sys.argv[1:])getword(word)os.system('say %s' % word);else:print 'usage:dict [word]'if __name__ == '__main__':reload(sys)sys.setdefaultencoding('utf8')main()
转载于:https://www.cnblogs.com/51reboot/p/4006040.html
Simple Python Dictionary :)相关推荐
- [转载] Python Dictionary用法小结
参考链接: Python字典dictionary | fromkeys()方法 一.Dictionary字典基本语法和操作 实例:dict = {'Alice': '2341', 'Beth': '9 ...
- Python Dictionary 字典
字典反转(reverse/inverse dictionary/mapping) Python字典反转就是将原字典的key作为value,而原来的value作为key,得到新的一个字典.如: 原字典为 ...
- python dictionary排序_对Python的字典进行排序
我们知道Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value ...
- Python Dictionary
1基本定义 Python dictionaries are also known as associative arrays or hash tables. The general syntax of ...
- python dictionary的遍历
d = {'x':1, 'y':3, 'z':2} for k in d: print d[k] 直接遍历k in d的话,遍历的是dictionary的keys. 2 字典的键可以是任何不可 ...
- python dictionary怎么用_python Dictionary字典使用
一.dictionary数据类型的结构是:{key1:value1, key2:value2, ...},即键值对.字典的健必须是不可更改的类型,如字符串.数字.元祖等:而值则可以是任意的数据类型,而 ...
- How to create a Python dictionary with double quotes as default quote format?
couples = [['jack', 'ilena'], ['arun', 'maya'], ['hari', 'aradhana'], ['bill', 'samantha']] pairs = ...
- CDS (W2) -- Features, Data, Text Processing
Features, Data, Text Processing 1. Features Examples of Features e.g. Home Type, Material Status, In ...
- python中定义数据结构_Python中的数据结构—简介
python中定义数据结构 You have multiples algorithms, the steps of which require fetching the smallest value ...
最新文章
- Yii2.0 RESTful API 之版本控制
- bzoj 1787 紧急集合
- open_basedir php.ini,关于PHP文件包含目录配置 open_basedir
- java中static详解
- java取网页源码_Java获取任意http网页源代码的方法
- 微软企业库连接access,web.config相对路径配置
- 从莱布尼茨到扎克伯格:算法和它许诺的美丽新世界
- 为什么农村出来的大学生大多混得比较差?
- linux里shell中的test代表的意义
- 【Speedtest】网络测速工具(支持命令行测试)
- JavaEE JavaSE JavaME的区别
- 19. 各种提权姿势总结
- Kconfig 和 Kbuild
- 福田中心区20个楼盘航拍全景
- Android中常用的一些颜色色值color整理
- CSS两种盒模型(标准盒模型IE盒模型)
- 洛谷 P1073 最优贸易 (分层图状态转移+SPFA,求最长路径;另附某dalao的超短代码:暴力+动规)
- 2021年创新实践部第一次培训电脑拆装总结
- CentOS7更换国内源以及安装补充更新源(安装nethogs)
- ztree插件树状图
热门文章
- 计算机制图 教学大纲,《计算机制图》课程教学大纲.doc
- sed、cut和awk命令的使用
- 创建型模式之Prototype
- 使用StarUML创建类图
- JDK动态代理和CGLIB代理的区别
- CHD-5.3.6集群上hive安装
- Laravel 事件侦听的几个方法 [Trait, Model boot(), Observer Class]
- JavaScriptjQuery.事件流
- [LeetCode] 565. Array Nesting
- Loadrunner12解决无法录制chrome及脚本为空问题