Convert StringIO to string
fredrik at pythonware.com
Mon Oct 16 18:07:32 CEST 2006
Jonathan Bowlas wrote:
> Ok, I think I'm explaining this badly because I've used getvalue() in
> the script I originally submitted to the list, see below:
> from StringIO import StringIO
> def generator_file(rsspath,titleintro,tickeropt):
> scripter.write('new rss_ticker(%s, %s, %s)\n' % (rsspath,
> titleintro, tickeropt))
> return scripter.getvalue()
> The problem is this script returns the following:
> new rss_ticker(www.bbc.co.uk, True, True) </script>
no, it doesn't. it returns "<script" etc. as a string. because that's
what getvalue() does.
if you end up getting < in the output, it's because you're passing
the output from generator_file(...) to some other part of your program
that does HTML escaping. StringIO has nothing to do with that, and no
amount of replacing inside generator_file() will change that.
> So what am I doing wrong?
coding under the influence of confusion?
can you post the code that calls generator_file() and the code that
writes the return value to the browser?
More information about the Python-list