Assigning output from a simple python statement
Wilson Fletcher
wilson at mclachlan.com.au
Thu Mar 16 02:14:57 EST 2000
I would like to execute an unknown python statement and store the output.
It will typically be a print statement. eg. "print 'Hello World'"
I won't know the statement until runtime becuase it will come from a
database. BUT I want to capture anything that goes to stdout and process
it.
I'm fairly new to python and the best I can come up with is:
# Assume the statement is stored in a dictionary with the key "code".
from os import popen
cmdDict['code'] = "print 'Hello World'"
line = popen( "python -c "+`cmdDict['code']` ).readline()
process( line )
Any gurus out there have better suggestions ?
thanks,
Wilson Fletcher
More information about the Python-list
mailing list