dynamically creating html code with python...

Timothy Grant timothy.grant at gmail.com
Mon Aug 11 13:59:20 EDT 2008


On Mon, Aug 11, 2008 at 10:05 AM,  <anartz at anartz.cjb.net> wrote:
> Hi,
>
> Thanks for your patience.
>
> I got the text displayed in the web browser with the following code:
>
> [CODE]
> f=StringIO.StringIO()
> f.write('<html><head><title>data analysis site</title></head><body>')
> f.write("<p>This is a trial test</p>")
> f.write("</body></html>")
>
> print "Content-type: text/html\n"
> print f.getvalue()
> f.close()
> [/CODE]
>
> Now I am trying to put both the image and the text together, but the following lines do not create the text with the chart that I expected.
>
> [CODE]
> f=StringIO.StringIO()
> f.write('<html><head><title>data analysis site</title></head><body>')
> f.write("<p>This is a trial test</p>")
> f.write(urllib.urlopen("http://localhost/myLibs/ChartLib.py",urllib.urlencode(TheData)))
> f.write("</body></html>")
>
> print "Content-type: text/html\n"
> print f.getvalue()
> f.close()
> [/CODE]
>
> I am wondering if urllib.urlopen is the command I need to revise.
>
> Thanks for the pointers as well. I will look into them.
>
>
>
>
> Jerry Hill <malaclypse2 at gmail.com> wrote :
>
>> On Mon, Aug 11, 2008 at 12:26 PM,  <anartz at anartz.cjb.net> wrote:
>> > I have tried calling a script containing the code below from a web browser and it did not get the text.
>>
>> You quoted my post that answered this question, but did not implement
>> either of the two solutions I suggested.  I continue to suggest that
>> you either: f.seek(0) before you f.read(), or that you replace
>> f.read() with f.getvalue().
>>
>> Also, you may want to read the docs on
>> StringIO - http://docs.python.org/lib/module-StringIO.html
>> File objects - http://docs.python.org/lib/bltin-file-objects.html
>>
>> --
>> Jerry


It looks to me like you are opening the url, but never retrieving the
content of the url.

I think you may have better luck with urllib2 which has a read() method.

http://docs.python.org/lib/urllib2-examples.html

-- 
Stand Fast,
tjg. [Timothy Grant]



More information about the Python-list mailing list