Python 入门demo第二篇
循环执行逻辑
1 #-*- coding: UTF-8 -*- 2 import time 3 import urllib2 4 5 6 def task(i): 7 urlstr='http://baidu.com' 8 html = urllib2.urlopen(urlstr,timeout=30).read() 9 # -*- coding: UTF-8 -*- 10 print '第',str(i),'次' 11 12 def tasking(j): 13 urlstr = 'http://baidu.com' 14 html = urllib2.urlopen(urlstr,timeout=30).read() 15 print '第',str(j),'次' 16 17 def timer(n): 18 i=0; 19 j=0; 20 while True: 21 print time.strftime('%Y-%m-%d %X', time.localtime()) 22 i+=1 23 j+=1 24 task(i) 25 tasking(j) 26 time.sleep(n) 27 28 29 if __name__ == '__main__': 30 timer(300)