用 Python 3 写的命令行百度词典
今天是第二天自己看关于Python了,看见一个Python2写的百度词典,我也用Python 3 写了一个。真的很小巧,呵呵,很好的语言。
不知道怎么上传代码格式的,就上传文本了:
# -*- coding: utf8 -*-
import urllib.parse
import urllib.request
def search(word):
#word = input("输入你要查询的单词:")
url="http://m.baidu.com/s?word="+word+"&ssid=0&from=0&bd_page_type=1&uid=frontui_1273397350_2416&mark=3"
s = (urllib.request.urlopen(url).read()).decode("UTF-8")
p=s[s.find("<div>")+5:s.find("</div>")-12]
q=p.split("<br/>")
for i in range(0,len(q)):
q[i]=q[i][0:(q[i].find("[<img"))]
q[i]=q[i][0:(q[i].find("<img"))]
print(q[i])
search(input("输入你要查询的单词:"))
search(input("输入你要查询的单词:"))
22:27:40
相关文档:
Install Python Eric IDE
1 Download following things
1) Python3.1
2) PyQt for python 3.1
(http://www.riverbankcomputing.co.uk/software/pyqt/download) I am using
PyQt-Py3.1-gpl-4.7.3-2.exe
3) Eric5 IDE
(http://eric-ide.python-projects.org/eric-download.html)
2 ......
队列:
与堆栈类似,通过python的列表类型来实现,参考 help(list)
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase'
print 'these items are:'
for item in shoplist:
print item,
shoplist.append('rice')
print 'my shopping list is now', shoplist
shoplist. ......
list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html 这几天看一下
python howto
恩。python documentation 确实很好很强大啊!
list.append(x)Add an item to the end of the list; equivalent to a[len(a):]&n ......
用Python提取文件夹下的特定扩展名的文件
不知道什么时候,网闲着没用,挂了个linux的视屏教程,里面有很多个文件夹,有很多无关的文件。这对于像我没收藏垃圾文件癖好的人来说,简直是 ......
英文版Dive in python可以在下面找到中文翻译http://linuxtoy.org/docs/dip/toc/index.html
模块的__name__,当模块被import时,其为模块的名字,当模块作为main执行的时候,其为__main__
词典的key是大小写敏感的。
List也支持重载+操作,用于将两个list连接起来,并返回一个List,因此它没有extended执行高效。list也+ ......