dynamically creating html code with python...

G

Guest

Hi,

how can I combine some dynamically generated html code (using python) with the output of a urllib.openurl() call?

I have tried to use the StringIO() class with .write functions, but it did not work. Below is the code that does not work.

Code:
f=StringIO.StringIO()
f.write('<html><head><title>data analysis</title></head><body>')
f.write(urllib.urlopen("http://localhost/path2Libs/myLibs.py", urllib.urlencode(TheData)))
f.write("</body></html>")

print "Content-type: text/html\n"
print f.read()
f.close()

What is wrong with this approach/code? Is there an easier way of doing it?

Thanks.
 
C

Carsten Haese

Hi,

how can I combine some dynamically generated html code (using python) with the output of a urllib.openurl() call?

I have tried to use the StringIO() class with .write functions, but it did not work. Below is the code that does not work.

Help us help you. "Does not work" is not a helpful description. Do you
get an error message? If so, what is the error message? Do you get an
unexpected result? If so, what is the unexpected result, and what is the
result you expected?
Is there an easier way of doing it?

Probably. You seem to be invoking a python program that's local to your
computer, so it's not quite clear why you're going the roundabout way of
serving it up through a web server. Then again, you're not telling us
the actual problem you're trying to solve, so we have no idea what the
best solution to that problem might be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top