What is the Python 3 equivalent of “python -m SimpleHTTPServer”

后端 未结 6 768
萌比男神i
萌比男神i 2020-11-28 00:19

What is the Python 3 equivalent of python -m SimpleHTTPServer?

6条回答
  •  不知归路
    2020-11-28 00:26

    Using 2to3 utility.

    $ 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
    

    Like many *nix utils, 2to3 accepts stdin if the argument passed is -. Therefore, you can test without creating any files like so:

    $ 2to3 - <<< "import SimpleHTTPServer"
    

提交回复
热议问题