[Tutor] re-directing print statements in exec
Toby Donaldson
tjd at sfu.ca
Wed Sep 24 02:49:22 EDT 2003
Hi all,
I am wondering if there is any easy way to make a print statement in an
exec statement get sent to a string instead of the console. For
instance,
>>> prog = """
r = 5
print 3.14 * r ** 2
"""
>>> exec prog
78.5
The result gets printed to the console. But instead, I'd like it to be
in a string.
Any suggestions?
Toby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20030924/a5224708/attachment.html
More information about the Tutor
mailing list