Re: execute python code and save the stdout as a string

2005-06-27 Thread jwaixs
Thank you, this really looks cool! -- http://mail.python.org/mailman/listinfo/python-list

execute python code and save the stdout as a string

2005-06-25 Thread jwaixs
Hello, I've a question. Can I execute a part of a python code and put it's output in a string? Something like this: s = s = exec print Hello World print s Greetz, Noud -- http://mail.python.org/mailman/listinfo/python-list

Re: execute python code and save the stdout as a string

2005-06-25 Thread Leif K-Brooks
jwaixs wrote: I've a question. Can I execute a part of a python code and put it's output in a string? import sys from cStringIO import StringIO def exec_and_get_output(code): ... old_stdout = sys.stdout ... sys.stdout = StringIO() ... try: ... exec code in {}, {}