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 社区有句俗语:“Python 自己带着电池。” 别自己写计时框架。Python 2.3以后 、具备一个叫做 timeit 的完美计时工具。DiveInto中的例子
>>> import timeit
>>> t = timeit.Timer("soundex.soundex('Pilgrim')",
...     "import soundex")   
>>> t.timeit()             ......
	
    
        
    
    
python 中的re 模块
正则表达式
就个人而言,主要用它来做一些复杂字符串分析,提取想要的信息
学习原则:够用就行,需要的时候在深入
现总结如下:
正则表达式中特殊的符号:
“.” 表任意字符
“^ ” 表string起始
“$” 表string 结束
“*” “+” & ......
	
    
        
    
    
Python代码 
import string, os, sys   
  
dir = '/var'  
print '----------- no sub dir'  
  
files = os.listdir(dir)   
for f in files:   
   ......
	
    
        
    
    1.可执行程序
os.system('pgrep %s > %s' % (process, output))
   pidfile = open("output", 'r')
   totalpid = len(pidfile.readlines())
   pidfile.close()
   if totalpid == 0 :
         &nbs ......