Python Challenge攻略之Level 5

攻略:

在网页源码中有着这么一段话

1
2
3
<peakhell src="banner.p">
<!-- peak hell sounds familiar ? -->
</peakhell>

这里包含有两个信息:数据文件banner.p以及pickle模块
pickle是Python的序列化模块,提供Python对象的序列化与反序列化

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env/python
#coding:utf8
'''
Created on May 13, 2013

@author: killua
@url: http://www.pythonchallenge.com/pc/def/peak.html
@target: http://www.pythonchallenge.com/pc/def/channel.html
'''

import urllib
import pickle

def read_page(url):
text = urllib.urlopen(url)
return text

def deserialization(text):
return pickle.loads(text)

if __name__ == '__main__':
text = open('./input/level05.in').read()
orgin_objects = deserialization(text)

#draw graph by lists
for obj in orgin_objects:
line = ''
for item in obj:
line += item[0] * item[1]
print line

完整代码:

Github:https://github.com/zhenlohuang/python-challenge

坚持原创技术分享,您的支持将鼓励我继续创作!