协慌网

登录 贡献 社区

什么是 Python 3 相当于 “python -m SimpleHTTPServer”

什么是python -m SimpleHTTPServer的 Python 3 等价物?

答案

来自文档

SimpleHTTPServer模块已合并到 Python 3.0 中的http.server中。将源转换为 3.0 时,2to3 工具将自动调整导入。

所以,你的命令是python3 -m http.server

相当于:

python3 -m http.server

使用 2to3 实用程序。

$ cat try.py
import SimpleHTTPServer

$ 2to3 try.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: Refactored try.py
--- try.py  (original)
+++ try.py  (refactored)
@@ -1 +1 @@
-import SimpleHTTPServer
+import http.server
RefactoringTool: Files that need to be modified:
RefactoringTool: try.py