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

2024-03-29 14:43:56 发布

您现在位置:Python中文网/ 问答频道 /正文

Python 3相当于python -m SimpleHTTPServer的是什么?


Tags: simplehttpserver
3条回答

相当于:

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

来自the docs

The SimpleHTTPServer module has been merged into http.server in Python 3.0. The 2to3 tool will automatically adapt imports when converting your sources to 3.0.

因此,您的命令是python -m http.server,或者根据您的安装,它可以是:

python3 -m http.server

相关问题 更多 >