Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想运行一个用 StringIO 完成的 memfile。有没有可能这样做?像这样的东西:
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()
这应该有效:
eval(memfile.open().read())
编辑:
事实证明exec是需要的,因为eval只接受表达式:
exec
eval
exec memfile