[Tutor] Critique and Question
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:
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 + my_tuple
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')
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor