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:<div>
<br></div><div><div>import os</div><div>import urllib.request</div><div>import re</div><div><br></div><div>url_root = '<a href="http://diveintopython3.ep.io/examples/">http://diveintopython3.ep.io/examples/</a>'</div>
<div>file_root = os.path.join(os.path.expanduser("~"), "diveintopython3", "examples")</div><div><br></div><div>main_page = urllib.request.urlopen(url_root).read()</div><div>main_page = main_page.decode("utf-8")</div>
<div><br></div><div>pattern = 'href="([^"].*?.)(py|xml)"'</div><div>matches = re.findall(pattern, main_page)</div><div>for my_tuple in matches:</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>this_file = my_tuple[0] + my_tuple[1] </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>data = urllib.request.urlopen(url_root + this_file).read()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>data = data.decode("utf-8")</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>with open(os.path.join(file_root, this_file), mode='w', encoding='utf-8') as a_file:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>a_file.write(data)</div>
<div><br></div>-- <br>Mark :)<br>
</div>