Python中的Python

时间:2012-06-01 12:56:29

标签: python subprocess

我正在尝试从Python脚本启动一个简单的服务器:

    server = Popen(['python' ,'-m', 'SimpleHTTPServer', '9090'], stderr=STDOUT, stdout=PIPE)
    output = server.communicate()[0]  # <- DEBUG

阅读输出,我看到了:

'/usr/bin/python: Import by filename is not supported.'

有什么问题?怎么解决?

1 个答案:

答案 0 :(得分:0)

我建议更改代码:

import SimpleHTTPServer
import SocketServer

PORT = 9090

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()