<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>some samples here<br><span><a target="_blank" href="http://nullege.com/codes/search?cq=urllib.request.urlopen">http://nullege.com/codes/search?cq=urllib.request.urlopen</a></span><br><br>- Purui<br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> ken barclay &lt;ken.barclay@att.net&gt;<br><b><span style="font-weight: bold;">To:</span></b> baypiggies@python.org<br><b><span style="font-weight: bold;">Sent:</span></b> Sat, December 19, 2009 10:40:59 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Baypiggies] Using urllib2 to print file contents
 line-by-line<br></font><br>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit; -x-system-font: none;" valign="top">I'm running the backend on a Centos box.<br><br>I do have a workaround but it requires an extra step from the user - I just print out the url on the output page, and when the user clicks the link, the browser takes care of loading the file into the browser and it looks exactly like it does in the file.<br><br>Would be nice to avoid that step but it's not critical - Thanks Aahz.<br><br>--- On <b>Sat, 12/19/09, Aahz <i>&lt;aahz@pythoncraft.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Aahz &lt;aahz@pythoncraft.com&gt;<br>Subject: Re: [Baypiggies] Using urllib2 to print file contents
 line-by-line<br>To: baypiggies@python.org<br>Date: Saturday, December 19, 2009, 4:22 PM<br><br><div class="plainMail">On Fri, Dec 18, 2009, ken barclay wrote:<br>&gt;<br>&gt; I'm trying to do
 something simple - I want to print the contents of<br>&gt; files that are staged on a web server back to the browser. I loop over<br>&gt; the file-like object that comes back in the response:<br>&gt;<br>&gt; ??????? import urllib2<br>&gt; ??????? req = urllib2.Request(href)<br>&gt; ??????? response = urllib2.urlopen(req)<br>&gt; ??????? for line in response:<br>&gt; ??????? print line<br>&gt; <br>&gt; But I want the lines to appear in the browser exactly like they do<br>&gt; in the file - with each one on a new line (because it's columnar<br>&gt; data.) The problem is: this approach doesn't work because the first<br>&gt; 'print' is printing out the whole response in one big stream (ignoring<br>&gt; newlines).<br><br>What OS are you on?&nbsp; You are probably running into newline variations,<br>and I'm not sure whether you can set universal newlines on an<br>already-opened file.<br>-- <br>Aahz (<a rel="nofollow">aahz@pythoncraft.com</a><span>)&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;<a target="_blank" href="http://www.pythoncraft.com/">http://www.pythoncraft.com/</a></span><br><br>Looking back over the years, after I learned Python I realized that I<br>never really had enjoyed programming before.<br>_______________________________________________<br>Baypiggies mailing list<br><a rel="nofollow">Baypiggies@python.org</a><br>To change your subscription options or unsubscribe:<br><span><a target="_blank" href="http://mail.python.org/mailman/listinfo/baypiggies">http://mail.python.org/mailman/listinfo/baypiggies</a></span><br></div></blockquote></td></tr></tbody></table></div></div>
<!-- cg24.c3.mail.sp2.yahoo.com compressed/chunked Thu Dec 17 21:14:59 PST 2009 -->
</div></body></html>