[Tutor] Critique and Question

Mark Lybrand mlybrand at gmail.com
Mon Nov 28 10:28:06 CET 2011

Okay, so I just started to learn Python.  I have been working through Dive
Into Python 3 and the Google stuff (great exercises IMHO, totally fun).
 However, with Dive, I had an issue with him referencing the files in the
example directory, which from the website seem very unhandy.  Although I
have since stumbled upon his GitHub, I made a Python script to grab those
files for me and it works great, with the exception of doubling the line
spacing.  So here is my code. I hope you critique the heck out of my and
that you point out what I did wrong to introduce double line-spacing.
 Thanks a bunch:

import os
import urllib.request
import re

url_root = 'http://diveintopython3.ep.io/examples/'
file_root = os.path.join(os.path.expanduser("~"), "diveintopython3",

main_page = urllib.request.urlopen(url_root).read()
main_page = main_page.decode("utf-8")

pattern = 'href="([^"].*?.)(py|xml)"'
matches = re.findall(pattern, main_page)
for my_tuple in matches:
this_file = my_tuple[0] + my_tuple[1]
data = urllib.request.urlopen(url_root + this_file).read()
data = data.decode("utf-8")
with open(os.path.join(file_root, this_file), mode='w', encoding='utf-8')
as a_file:

Mark :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111128/4af8cc5a/attachment.html>

More information about the Tutor mailing list