[Tutor] Critique and Question

Dave Angel d at davea.name
Mon Nov 28 18:46:40 CET 2011

On 11/28/2011 12:31 PM, Mark Lybrand wrote:
> Sorry for not providing all the required info. I am running python 3.2 on
> windows vista. I determined the files are double spaced by viewong them
> (random sampling) in notepad++. Not double spaced on server by downloading
> one in the browser. Can I use the 'Wu' flag when writing.  I might just be
> 'w'-ing. I will look when I get home.
> Thanks
> Mark
> Also a little bummed that subprocess module doesn't appear to work on
> windows. I probably (hopefully) won't need it, but it still bums me.
>   On Nov 28, 2011 4:27 AM, "Dave Angel"<d at davea.name>  wrote:
>> On 11/28/2011 04:28 AM, Mark Lybrand wrote:
>>> 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/<http://diveintopython3.ep.io/examples/>
>>> '
>>> file_root = os.path.join(os.path.**expanduser("~"), "diveintopython3",
>>> "examples")
>>> 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:
>>> a_file.write(data)
>>>   You don't tell what your environment is, nor how you decide that the
>> file is double-spaced.  You also don't mention whether you're using Python
>> 2.x or 3.x
>> My guess is that you are using a Unix/Linux environment, and that the Dive
>> author(s) used Windows.  And that your text editor is interpreting the
>> You can figure out what is actually in the file by using repr() on bytes
>> read from the file in binary mode.  Exactly how you do that will differ
>> between Python 2.x and 3.x
You put your comments BEFORE the quoted text (top-posted), so they 
appear out of order.  In a forum like this one, the convention is to add 
your remarks after the part you're quoting.

Use a hex viewer to see what the file actually looks like.  My guess 
doesn't apply, since if you had the reverse problem (reading text file 
in a Windows program that was generated in Linux)  MIGHT have a symptom 
of showing all the lines concatenated.  That's not what you describe.

if you don't have a hex viewer, you could write one, or you could just 
write a function that uses repr() on the first 200 bytes of the file.

As for subprocess, why would you guess that it doesn't work on Windows? 
  Perhaps if there's something specific that you've tried, you could 
start a new thread showing what you tried and how it misbehaved.  Don't 
forget to supply your environment information as well as the source code 
you tried, and any stack trace from the crash.



More information about the Tutor mailing list