문제

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