介绍
这篇文章给大家分享的是有关python代码运行助手的使用方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
python代码运行助手是能在网页上运行python语言的工具。因为python的运行环境在很多教程里都是用dos的,黑乎乎的界面看的有点简陋,所以出了这python代码运行助手,作为ide。
实际上,python代码运行助手界面只能算及格分,如果要找ide,推荐使用jupyter.jupyter被集成到蟒蛇里,只要安装了anacoda就能使用了。
1,要打开这运行助手首先要下载一个learning.py,如果找不到可以复制如下代码另存为”学习。py”,编辑器用崇高,或者notepad++。
# !/usr/bin/env python3 #,- *安康;编码:,utf-8 - *安康; " # 39;& # 39;& # 39; learning.py A Python 3, tutorial 得到http://www.liaoxuefeng.com 用法:, python3 learning.py & # 39;& # 39;& # 39;, import 系统 , def check_version (): ,,,v =sys.version_info ,,,if v.major ==, 3,以及v.minor 祝辞=,4: ,,,,,,,return 真实的 ,,,print (& # 39; Your  current python is % d % d只Please use python 3.4 # 39;公司,%,(v.major, v.minor)) ,,,return 错误的 , if not  check_version (): ,,,退出(1) , import 操作系统,io, json,子流程,tempfile 得到urllib import 解析 得到wsgiref.simple_server import  make_server , EXEC =sys.executable PORT =39093 时间=HOST & # 39; local.liaoxuefeng.com: % d # 39; %,港口 时间=TEMP tempfile.mkdtemp(后缀=& # 39;_py& # 39;,,前缀=& # 39;learn_python_& # 39;) INDEX =0 , def main (): ,,,httpd =, make_server(& # 39; 127.0.0.1 # 39;,,港口,应用程序) ,,,print (& # 39; Ready  for Python code 提醒port % d…& # 39;, %,端口) ,,,httpd.serve_forever () , def get_name (): ,,,global 指数 ,,,INDEX =, INDEX + 1 ,,,return & # 39; test_ % d # 39; %,指数 , def write_py(名称,代码): ,,,fpath =, os.path.join (TEMP, & # 39; % s.py& # 39;, %,名称) ,,,with 开放(fpath, & # 39; w # 39;,,编码=& # 39;utf - 8 # 39;), as f: ,,,,,,,f.write(代码) ,,,print (& # 39; Code  wrote :, % & # 39;, %, fpath) ,,,return fpath , def 解码(s): ,,,试一试: ,,,,,,,return s.decode (& # 39; utf - 8 # 39;) ,,,except UnicodeDecodeError: ,,,,,,,return s.decode (& # 39; gbk # 39;) , def 应用程序(围住,start_response): ,,,host =, environ.get (& # 39; HTTP_HOST& # 39;) ,,,method =, environ.get (& # 39; REQUEST_METHOD& # 39;) ,,,path =, environ.get (& # 39; PATH_INFO& # 39;) ,,,if method ==, & # 39;得到# 39;,以及path ==, & # 39;/& # 39;: ,,,,,,,start_response(& # 39; 200,好吧,,,((& # 39;内容类型# 39;,,& # 39;text/html # 39;))) ,,,,,,,return (b) # 39; & lt; html> & lt; head> & lt; title> Learning Python & lt;/head> & lt; body> & lt; form 方法=皃ost", action=?run"比; ,,,,,,,& lt; textarea name=癱ode",风格=翱矶?90%;高度:,600 px"祝辞& lt;/textarea> & lt; p> & lt; button 类型=皊ubmit"祝辞Run ,,,,,,,& lt;/p> & lt;/form> & lt;/body> & lt;/html> & # 39;] ,,,if method ==, & # 39;得到# 39;,以及path ==, & # 39;/env # 39;: ,,,,,,,start_response(& # 39; 200,好吧,,,((& # 39;内容类型# 39;,,& # 39;text/html # 39;))) ,,,,,,,L =, (b) # 39; & lt; html> & lt; head> & lt; title> ENV & lt;/head> & lt; body> & # 39;】 ,,,,,,,for k, v 拷贝environ.items (): ,,,,,,,,,,,p =, & # 39; & lt; p> % s =, % & # 39;, %, (k, str (v)) ,,,,,,,,,,,L.append (p.encode (& # 39; utf - 8 # 39;)) ,,,,,,,L.append (b # 39; & lt;/html> & # 39;) ,,,,,,,return L null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null nullpython代码运行助手的使用方法