python challenge level6
2009. 9. 21. 01:25
http://www.pythonchallenge.com/pc/def/channel.html
지퍼가 반집 열려있는 사진 한장을 달랑 볼 수 있다. 소스를 보니 zip 이라는 단어가 적혀 있었다.
혹시나 해서 아래의 url 을 입력해 보았다.
http://www.pythonchallenge.com/pc/def/zip.html
yes. find the zip.
zip 파일을 찾으란다. 몇번의 삽질 끝에
http://www.pythonchallenge.com/pc/def/channel.zip 에서 파일을 받을 수 있었다.
이 압축파일안에는 텍스트 파일들이 들어있는데 그안에는 숫자들이 적혀있다.
Readme 파일을 읽어보면 앞서 풀었던 문제와 거의 유사한 형태임을 알 수 있다.
90052부터 순서대로 파일을 읽어나가던 중 한가지 문제에 봉착했다.
숫자 대신에 Collect the comments 라는 글귀가 적혀있는 것이다. 한참 골머리를 앓다가
빵집으로 열어서 봤더니 설명 탭에 한글자씩 적혀있는것이 보인다. 아 이게 comment 구나 싶어
한글자씩 모아서 합쳐보았더니 hockey 라는 단어가 화면에 크게 출력되었다.
import zipfile import re def get_comment(file_name): tmp = file.getinfo(file_name) return tmp.comment try: file = zipfile.ZipFile("channel.zip","r") nothing = '90052' txt = '.txt' result = '' while 1: name = nothing + txt data = file.read(name) temp = re.findall("[0-9]+",data) nothing = temp[0] result += get_comment(name) except: print '' print result
포인트는 zipfile 인스턴스를 만든후 getinfo method로 comment attributes를 뽑아내면 된다.
'War game > pythonchallenge' 카테고리의 다른 글
pythonchallenge level11 (0) | 2009.10.22 |
---|---|
pythonchallenge level10 (0) | 2009.10.20 |
pythonchallenge level9 (0) | 2009.10.16 |
pythonchallenge level8 (0) | 2009.10.16 |
pythonchallenge level7 (0) | 2009.10.16 |
python challenge level5 (0) | 2009.08.27 |
pythonchallenge level4 (0) | 2009.08.20 |
pythonchallenge level3 (0) | 2009.08.19 |
pythonchallenge level2 (0) | 2009.08.17 |
pythonchallenge level1 (0) | 2009.08.17 |