您要为一个终端或一个蟒蛇的壳呢?
对于Popen和Subprocess你已经有了一些有用的答案,如果你已经计划使用它,你也可以使用pexpect。
#for multiple python shells
import pexpect
#make your commands however you want them, this is just one method
mycommand1 = "print 'hello first python shell'"
mycommand2 = "print 'this is my second shell'"
#add a "for" statement if you want
child1 = pexpect.spawn('python')
child1.sendline(mycommand1)
child2 = pexpect.spawn('python')
child2.sendline(mycommand2)
,你想要让尽可能多的孩子/壳,然后使用child.before()或child.after()得到您的答复。
当然,您想要添加要发送的定义或类而不是“mycommand1”,但这只是一个简单的示例。
如果你想让一帮在Linux终端,你只需要在pextpext.spawn线更换的python
注:我没有测试上面的代码。我只是从过去的经验中回答。