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()

没有正确的解决方案

其他提示

This should work:

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

EDIT:

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

exec memfile
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top