Python Challenge Level 6

Source: Internet
Author: User

Ashamed, this topic is to refer to other people's blog made out, the main difficulty in

1. How to get a zip file

2.comments is a thing, the original author also in the blog "What the hell is the comments?"

From this problem, I find that

1. The information is not necessarily only on this page, you can modify the URL to obtain additional information.

2. For information that you cannot understand in the tip, such as "comments" in the subject, you can try searching in the Python doc (this is often the key to solving the problem), and Python doc can be found in your installation folder

The code is as follows:

1 #http://www.pythonchallenge.com/pc/def/channel.html2 #Author: [Email protected]3 ImportOS4 ImportSYS5 ImportZipFile6 ImportRe7 Importurllib.request8 ImportUrllib.response9 defDownloadFile (URL):TenResponse =urllib.request.urlopen (URL) OneZP = open ('Channel.zip','WB') A Zp.write (Response.read ()) - zp.close () -  the defAnalysis (chzip,arcname): -ZP = ZipFile. ZipFile (Chzip,'R') -Zp.extractall (path=arcname) - zp.close () +Flist =Os.listdir (arcname) -      forFinchflist: +Txfile = open (Arcname+f,'R') A          forLineinchTxfile: at             Print(line) -  - defFlow (Chzip,beg): -ZP = ZipFile. ZipFile (Chzip,'R') -NameList =zp.namelist () -Nowfile =Beg inDirpath ='./channel/' -Pat = Re.compile ('\d{1,5}') toComments ="' +      whileTrue: -fname = Nowfile +'. txt' theComments + = str (zp.getinfo (fname). comment,encoding='Utf-8') *Zp.extract (fname,path=Dirpath) $f = open (Dirpath + fname,'R')Panax NotoginsengContent =F.readline () -Matchs =pat.findall (content) the  +         ifLen (matchs)! =0: ANowfile =Matchs[0] the         Else: +              Break -     returnComments $ if __name__=='__main__': $Nowurl = R'Http://www.pythonchallenge.com/pc/def/channel.zip' - DownloadFile (Nowurl) -     #Analysis (' Channel.zip ', './channel/') the     Print(Flow ('Channel.zip','90052'))

Python Challenge Level 6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.