HTML will not generally display embedded newlines in text. Alans's suggestion of wrapping the output in <pre> is good, or you could do something like:<div><br></div><div>response.read().split("\n").join("<br/>")</div>
<div><br></div><div>to insert HTML linebreaks. If the data is truly columnar though a <table> would be most appropriate, though that would be slightly more complicated.</div><div><br></div><div>-Adam<br><br><div class="gmail_quote">
On Fri, Dec 18, 2009 at 7:39 PM, ken barclay <span dir="ltr"><<a href="mailto:ken.barclay@att.net">ken.barclay@att.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">Hello,<br><br>I'm trying to do something simple - I want to print the contents of files that are staged on a web server back to the browser. I loop over the file-like object that comes back in the response:<br>
<br> import urllib2<br> req = urllib2.Request(href)<br> response = urllib2.urlopen(req)<br> for line in response:<br> print line<br><br>But I want the lines to appear in the browser exactly like they do in the file - with each one on a new line (because it's columnar data.) The problem is: this approach doesn't work because the first 'print' is printing out the whole response in one big stream (ignoring newlines).<br>
<br>I tried the other techniques
at <a href="http://docs.python.org/library/urllib2.html" target="_blank">http://docs.python.org/library/urllib2.html</a> still get the same result. Suggestions?<br><br>Thanks<br><font color="#888888">Ken<br></font></td>
</tr></tbody></table><br>_______________________________________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br></blockquote></div><br><br clear="all"><br>-- <br>Adam Hupp | <a href="http://hupp.org/adam/">http://hupp.org/adam/</a><br>
</div>