Python: python写的一个简单网络词典
闲来无事, 玩玩python...
是采用有道翻译, 然后抓取网页的.
import re, urllib
url="http://dict.youdao.com/search?le=eng&q="
print ("input q to exit")
while 1:
word = raw_input(">>>")
if word=="q":
exit()
else:
word = word.replace(' ', '+')
url += word
url += "&tab=chn&keyfrom=dict.top"
s = urllib.urlopen(url).read()
comm1 = re.compile(';</td><td class="attributem1web">.*?</td>')
result=comm1.findall(s)
comm2 = re.compile(r'<td class="dttitle2"><font color="#013694"><b>.*?<\/b><\/font><\/td>')
related = comm2.findall(s)
#find the result
if result:
print 'meaning:'
for i in result:
temp = i.decode('utf8').encode('cp936')
temp = temp[33:]
temp = temp[:-5]
print temp
print '\n'
#fine the matters
if related:
print 'related:'
for i in related:
temp = i.decode('utf8').encode('cp936')
temp = temp[46:]
temp = temp[:-16]
print temp
print '\n'
else:
print 'no such word!'
相关文档:
下载了很多压缩文件,就写了一个脚本
在Python中使用winrar命令,所以一般压缩文件都支持
有些压缩文件Python中还没有相应的库
你得先把winrar添加到path环境变量中
把代码保存为rar.py
在dos下使用,如:rar.py "D:\A B\C" mkdir
#rar.py
#decompress with winrar
#arguments :filename directory opt
# op ......
综述
多线程是程序设计中的一个重要方面,尤其是在服务器Deamon程序方面。无论何种系统,线程调度的开销都比传统的进程要快得多。
Python可以方便地支持多线程。可以快速创建线程、互斥锁、信号量等等元素,支持线程读写同步互斥。美中不足的是,Python的运行在Python
虚拟机上,创建的多线程可 ......
Python的os模块,包含了普遍的操作系统功能,这里主要学习与路径相关的函数:
os.listdir(dirname):列出dirname下的目录和文件
os.getcwd():获得当前工作目录
os.curdir:返回当前目录('.')
os.chdir(dirname):改变工作目录到dirname
os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false
......
1.可执行程序
os.system('pgrep %s > %s' % (process, output))
pidfile = open("output", 'r')
totalpid = len(pidfile.readlines())
pidfile.close()
if totalpid == 0 :
&nbs ......