Question

I want to run a memfile done with StringIO. Is there any possibility for doing it? something like this:

import StringIO

memfile = StringIO.StringIO()
memfile.write("print 'hello world'")

#with diskfiles I would do:
#os.system('python memfile') ?
#subprocess.Popen('memfile', shell=True)
memfile.close()

No correct solution

OTHER TIPS

This should work:

eval(memfile.open().read())

EDIT:

It turns out exec is needed, as eval accepts expressions only:

exec memfile
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top