本文翻译自:What is the Python 3 equivalent of “python -m SimpleHTTPServer”

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


#1楼

参考:https://stackoom.com/question/XKX1/什么是Python-相当于-python-m-SimpleHTTPServer


#2楼

Using 2to3 utility. 使用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

#3楼

In addition to Petr's answer, if you want to bind to a specific interface instead of all the interfaces you can use -b/--bind flag. 除了Petr的答案,如果你想绑定到特定的接口而不是所有接口,你可以使用-b / - bind标志。

python -m http.server 8000 --bind 127.0.0.1

The above snippet should do the trick. 上面的片段应该可以解决问题。 8000 is the port number. 8000是端口号。 80 is used as the standard port for HTTP communications. 80用作HTTP通信的标准端口。


#4楼

In one of my projects I run tests against Python 2 and 3. For that I wrote a small script which starts a local server independently: 在我的一个项目中,我针对Python 2和3运行测试。为此,我编写了一个小脚本,它独立启动本地服务器:

$ python -m $(python -c 'import sys; print("http.server" if sys.version_info[:2] > (2,7) else "SimpleHTTPServer")')
Serving HTTP on 0.0.0.0 port 8000 ...

As an alias: 作为别名:

$ alias serve="python -m $(python -c 'import sys; print("http.server" if sys.version_info[:2] > (2,7) else "SimpleHTTPServer")')"
$ serve
Serving HTTP on 0.0.0.0 port 8000 ...

Please note that I control my Python version via conda environments , because of that I can use python instead of python3 for using Python 3. 请注意,我通过conda环境控制我的Python版本,因为我可以使用python而不是python3来使用Python 3。


#5楼

相当于:

python3 -m http.server

#6楼

From the docs : 来自文档 :

The SimpleHTTPServer module has been merged into http.server in Python 3.0. SimpleHTTPServer模块已合并到Python 3.0中的http.server中。 The 2to3 tool will automatically adapt imports when converting your sources to 3.0. 将源转换为3.0时,2to3工具将自动调整导入。

So, your command is python -m http.server , or depending on your installation, it can be: 所以,你的命令是python -m http.server ,或者根据你的安装,它可以是:

python3 -m http.server

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

  1. Python学习笔记1 Python基础

    第1章 Python基础 1.1 Python概述及版本介绍 1.Python是一种面向对象的解释型计算机程序设计语言(解释型语言源代码->解释器逐行解释每一句源代码) 2.优点:高级语言.可移 ...

  2. 0基础学好python难不难_零基础学习Python难不难?Python有什么优势?

    原标题:零基础学习Python难不难?Python有什么优势? Python是一种计算机程序设计语言.首先,我们普及一下编程语言的基础知识.用任何编程语言来开发程序,都是为了让计算机干活,比如下载一个 ...

  3. java python算法_用Python,Java和C ++示例解释的排序算法

    java python算法 什么是排序算法? (What is a Sorting Algorithm?) Sorting algorithms are a set of instructions t ...

  4. Python培训教程:Python有哪些比较重要的内置函数?

    学习Python技术或者参加Python工作的小伙伴们应该都知道,在Python编程语言中会经常出现很多内置函数,很少有人清楚这些函数,但是它的功能是不可小觑的,下面小编就为大家详细介绍一下Pytho ...

  5. Python培训分享:Python新版本中的6个新特性

    Python在几年做了一个全面的升级,此次Python升级中有6个新特性,本期小编为大家介绍的Python培训教程就是关于介绍Python新版本中的6个新特性的,来看看下面的详细介绍. Python培 ...

  6. Python培训分享:Python发展前景怎么样?

    最近学习Python技术的同学越来越多,大家对于Python技术比较关注的两个点,就是Python技术好不好学,Python就业前景好不好,那么本文针对Python发展前景怎么样这个问题为大家做下详细 ...

  7. Python培训常识:Python面试中常被问到的几种设计模式要知道

    学习Python技术大家都是为了日后能够找到适合自己的工作岗位,那么除了要学习好Python技术外,对于面试环节的问题也要有所了解,本期小编为大家介绍的Python培训教程就算关于Python面试中常 ...

  8. Python培训分享:Python内置标准异常及其解析

    本期小编为大家带来的Python培训教程是关于"Python内置标准异常及其解析"的内容,我们都知道,在Python技术运作下,总会出现一些Python无法正常处理的程序时就会发生 ...

  9. Python培训分享:python爬虫可以用来做什么?

    爬虫又被称为网络蜘蛛,它可以抓取我们页面的一些相关数据,近几年Python技术的到来,让我们对爬虫有了一个新的认知,那就是Python爬虫,下面我们就来看看python爬虫可以用来做什么? Pytho ...

  10. Python培训教程之Python基础知识点梳理

    Python语言是入门IT行业比较快速且简单的一门编程语言,学习Python语言不仅有着非常大的发展空间,还可以有一个非常好的工作,下面小编就来给大家分享一篇Python培训教程之Python基础知识 ...

最新文章

  1. 为什么Python发展这么快,有哪些优势?
  2. 算法------最接近的三数之和
  3. 青龙依赖环境一键安装部署
  4. Golang的指针类型
  5. bestcoder Delete
  6. SQL 触发器的使用
  7. [转]解决Android studio升级到3.5的一些问题
  8. 安徽计算机学业水平测试内容,【2017年整理】安徽省学业水平测试信息技术(必修)知识点.doc...
  9. 骗子是怎样将1G硬盘变成120G的
  10. react ssr方法
  11. c语言输出语句形式,c语言输出语句是什么
  12. 果然,ChatGPT 还是被拿去搞黄色了...
  13. 单利 java_JAVA中的单利
  14. document.documentElement对象
  15. 微信运动的刷步思路+云部署
  16. [linux无线子系统]主动扫描之发送Probe Request帧
  17. 2021Java进阶学习资料!熬夜整理小米Java面试题
  18. 如果有一天我不更新博客了
  19. 禁止后退键(Backspace)终极方案
  20. 如何透过上层div点击下层的元素

热门文章

  1. Observable.OnSubscribe 的理解
  2. openfire 插件开发
  3. android canves rotate 详解
  4. 新入公司 问问题 ,快速了解代码的方法
  5. 从URL输入到页面展现,过程中发生了什么?
  6. 第八周项目一-数组作数据成员(2)
  7. java静态代码块和静态变量_java静态变量和静态代码块的加载顺序
  8. Java之HashMap源码解析1
  9. ubuntu下机器学习工具的安装使用
  10. iOS架构-C/C++lame库在Mac下编译通用静态库.a库(13)