0

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()
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

This should work:

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

EDIT:

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

exec memfile
piokuc
  • 25,594
  • 11
  • 72
  • 102