python代码运行助手是能在网页上运行python语言的工具。因为python的运行环境在很多教程里都是用dos的,黑乎乎的界面看的有点简陋,所以出了这python代码运行助手,作为ide。

实际上,python代码运行助手界面只能算及格分,如果要找ide,推荐使用jupyter。jupyter被集成到ANACONDA里,只要安装了anacoda就能使用了。

1、要打开这运行助手首先要下载一个learning.py,如果找不到可以复制如下代码另存为“learning.py”,编辑器用sublime、或者notepad++。#!/usr/bin/env python3

# -*- coding: utf-8 -*-

r'''

learning.py

A Python 3 tutorial from http://www.liaoxuefeng.com

Usage:

python3 learning.py

'''

import sys

def check_version():

v = sys.version_info

if v.major == 3 and v.minor >= 4:

return True

print('Your current python is %d.%d. Please use Python 3.4.' % (v.major, v.minor))

return False

if not check_version():

exit(1)

import os, io, json, subprocess, tempfile

from urllib import parse

from wsgiref.simple_server import make_server

EXEC = sys.executable

PORT = 39093

HOST = 'local.liaoxuefeng.com:%d' % PORT

TEMP = tempfile.mkdtemp(suffix='_py', prefix='learn_python_')

INDEX = 0

def main():

httpd = make_server('127.0.0.1', PORT, application)

print('Ready for Python code on port %d...' % PORT)

httpd.serve_forever()

def get_name():

global INDEX

INDEX = INDEX + 1

return 'test_%d' % INDEX

def write_py(name, code):

fpath = os.path.join(TEMP, '%s.py' % name)

with open(fpath, 'w', encoding='utf-8') as f:

f.write(code)

print('Code wrote to: %s' % fpath)

return fpath

def decode(s):

try:

return s.decode('utf-8')

except UnicodeDecodeError:

return s.decode('gbk')

def application(environ, start_response):

host = environ.get('HTTP_HOST')

method = environ.get('REQUEST_METHOD')

path = environ.get('PATH_INFO')

if method == 'GET' and path == '/':

start_response('200 OK', [('Content-Type', 'text/html')])

return [b'

Learning Python

Run

']

if method == 'GET' and path == '/env':

start_response('200 OK', [('Content-Type', 'text/html')])

L = [b'

ENV']

for k, v in environ.items():

p = '

%s = %s' % (k, str(v))

L.append(p.encode('utf-8'))

L.append(b'')

return L

if host != HOST or method != 'POST' or path != '/run' or not environ.get('CONTENT_TYPE', '').lower().

startswith('application/x-www-form-urlencoded'):

start_response('400 Bad Request', [('Content-Type', 'application/json')])

return [b'{"error":"bad_request"}']

s = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH']))

qs = parse.parse_qs(s.decode('utf-8'))

if not 'code' in qs:

start_response('400 Bad Request', [('Content-Type', 'application/json')])

return [b'{"error":"invalid_params"}']

name = qs['name'][0] if 'name' in qs else get_name()

code = qs['code'][0]

headers = [('Content-Type', 'application/json')]

origin = environ.get('HTTP_ORIGIN', '')

if origin.find('.liaoxuefeng.com') == -1:

start_response('400 Bad Request', [('Content-Type', 'application/json')])

return [b'{"error":"invalid_origin"}']

headers.append(('Access-Control-Allow-Origin', origin))

start_response('200 OK', headers)

r = dict()

try:

fpath = write_py(name, code)

print('Execute: %s %s' % (EXEC, fpath))

r['output'] = decode(subprocess.check_output([EXEC, fpath], stderr=subprocess.STDOUT, timeout=5))

except subprocess.CalledProcessError as e:

r = dict(error='Exception', output=decode(e.output))

except subprocess.TimeoutExpired as e:

r = dict(error='Timeout', output='执行超时')

except subprocess.CalledProcessError as e:

r = dict(error='Error', output='执行错误')

print('Execute done.')

return [json.dumps(r).encode('utf-8')]

if __name__ == '__main__':

main()

2、再用一个记事本写如下的代码:@echo off

python learning.py

pause

另存为‘运行.bat’

3、把“运行.bat”和“learning.py”放到同一目录下。

4、双击运行“运行.bat",之后会弹出黑色的dos窗口,这个窗口不要关闭。

5、输入网址对应的网址和端口,整个过程就完成了。

python学习网,大量的免费python视频教程,欢迎在线学习!

origin python控制台怎么用_python代码运行助手如何使用相关推荐

  1. origin python控制台怎么用_python如何使用代码运行助手

    python代码运行助手是能在网页上运行python语言的工具.因为python的运行环境在很多教程里都是用dos的,黑乎乎的界面看的有点简陋,所以出了这python代码运行助手,作为ide. 实际上 ...

  2. python代码运行助手是什么业务_python代码运行助手怎么使用()

    python代码运行助手怎么使用 #/usr/bin/env python3 # -*- coding: utf-8 -*- r''' learning.py A Python 3 tutorial  ...

  3. python代码运行助手是什么业务_Python代码运行助手

    Python代码运行助手可以让你在线输入Python代码,然后通过本机运行的一个Python脚本来执行代码.原理如下: 在网页输入代码: 点击Run按钮,代码被发送到本机正在运行的Python代码运行 ...

  4. python手机版打了代码运行不了-如何用iPad运行Python代码?

    代码在我的Macbook电脑上跑,没有问题.还拿到学生的Windows 7上跑,也没有问题.这才上传到了Github. 在发布的教程文章里,我也已经把安装软件包的说明写得非常详细. 还针对 Anaco ...

  5. python手机版打了代码运行不了-android手机安装python并写代码运行

    整理自已手机通过termux装python编写代码遇到的一些问题及解决方法. 手机安装termux:如图,我手机上的 不要用apt update ,apt upgrade 我之前就是用了这两个命令就装 ...

  6. python如何撤销上一步_python代码运行到某一步能返回到前面某一步吗?

    展开全部 有. Eclipse里编程代码,返回上一步的快捷键是636f70793231313335323631343130323136353331333365653261alt+←箭头. eclips ...

  7. python代码运行顺序_python 代码运行顺序问题?

    Thread.join([timeout]) Wait until the thread terminates. This blocks the calling thread until the th ...

  8. python识别latex公式_Python代码转Latex公式,这个开源库用一行代码帮你搞定

    来源:机器之心 数学是数据科学和机器学习的重要基础,数学运算的结果对于机器学习项目而言是至关重要的.在编写代码时,我们常常需要定义数学公式的计算形式.像 S=r^2 这样简单的数学公式,大概不会出现拼 ...

  9. python手机版打了代码运行不了-三款可以在安卓手机上运行Python代码的软件

    导语 READ 我相信大家平时大多数时间肯定都是在电脑上面敲Python代码,有时候出门外或者不方便使用电脑的时候,你是否曾想用手机就能编写和运行Python代码呢?本文将会介绍3款不同的安卓软件帮忙 ...

最新文章

  1. 在 Ubuntu Linux 下搜索文件和文件内容
  2. 解读《信息系统灾难恢复规范》---转
  3. 6、Gerrit插件
  4. hdu2553 N皇后问题-dfs回溯剪枝+打表
  5. centos7安装svn客户端和使用
  6. OpenCV_08 边缘检测:Sobel检测算子+Laplacian算子+Canny边缘检测
  7. 1.9 _07 不与最大数相同的数字之和 python
  8. 迭代器、生成器、函数递归与二分法
  9. 用 c 写 CGI 程序简要指南
  10. 帧中继环境下Ping的实现
  11. LR 报错误: C interpreter run time error: Error -- Unresolved symbol : vuser_end解决方法
  12. IDEA类注释模板设置
  13. Uint 和 int 的区别
  14. 付款码支付-微信和支付宝付款码类型标识
  15. 第二篇:读曹德旺《心若菩提》
  16. 邵东一中2021年高考成绩查询,湖南邵阳2020高考成绩,邵东一中势头强劲,包揽邵阳市文理状元...
  17. mysql登录如何重置密码忘记_MySql登陆密码忘记了怎么办?MySQL重置root密码方法...
  18. 程序员年薪20万、30万、40万都是什么样的体验?
  19. 使用树莓派PICO点灯
  20. 《MA‑CRNN: a multi‑scale attention CRNN for Chinese text line recognition in natural scenes》论文阅读

热门文章

  1. Linux的常见问题解答和管理技巧2
  2. “梦幻海陆空”三军联合军事演习国防教育活动方案
  3. c语言程序中的函数的函数名,一个C语言程序是由一个或多个函数组成的,其中必须包含一个函数,函数名是mian。...
  4. think php5 volist,volist
  5. 2.css动画(空间转换,动画)
  6. Shell 数组遍历的3种方法
  7. 越穷越尖酸#65380;越丑越刻薄
  8. Tomcat下web项目部署方式
  9. IT痴汉的工作现状15-低级错误
  10. alexa 排名查询 webservice