Python Challenge 6
时间:2010-08-15 来源:Ray Z
http://www.pythonchallenge.com/pc/def/channel.html
从http://www.pythonchallenge.com/pc/def/channel.zip下载channel.zip
code 1 >>> import zipfile, re2 >>> start = '90052'
3 >>> r = 'Next nothing is (\d+)'
4 >>> file = zipfile.ZipFile('D:\channel.zip')
5 >>> f = "%s.txt"
6 >>> c = []
7 >>> while True:
8 try:
9 start = re.search(r, file.read(f % start)).group(1)
10 except:
11 print file.read(f % start)
12 break
13 c.append(file.getinfo(f % start).comment)
14
15
16 Collect the comments.
17 >>> print "".join(c)
18 ***************************************************************
19 ****************************************************************
20 ** **
21 ** OO OO XX YYYY GG GG EEEEEE NN NN **
22 ** OO OO XXXXXX YYYYYY GG GG EEEEEE NN NN **
23 ** OO OO XXX XXX YYY YY GG GG EE NN NN **
24 ** OOOOOOOO XX XX YY GGG EEEEE NNNN **
25 ** OOOOOOOO XX XX YY GGG EEEEE NN **
26 ** OO OO XXX XXX YYY YY GG GG EE NN **
27 ** OO OO XXXXXX YYYYYY GG GG EEEEEE NN **
28 ** OO OO XX YYYY GG GG EEEEEE NN **
29 ** **
30 ****************************************************************
31 **************************************************************
相关阅读 更多 +