欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Python代码运行助手

Python代码运行助手可以让你在线输入Python代码,然后通过本机运行的一个Python脚本来执行代码。原理如下:

  • 在网页输入代码:

  • 点击Run按钮,代码被发送到本机正在运行的Python代码运行助手;

  • Python代码运行助手将代码保存为临时文件,然后调用Python解释器执行代码;

  • 网页显示代码执行结果:

下载

点击右键,目标另存为:learning.py (已保存为自己的附件)

备用下载地址:learning.py  (已保存为自己的附件)

运行

在存放learning.py的目录下运行命令:

C:\Users\michael\Downloads> python learning.py

如果看到Ready for Python code on port 39093...表示运行成功,不要关闭命令行窗口,最小化放到后台运行即可:

试试效果

需要支持HTML5的浏览器:

  • IE >= 9

  • Firefox

  • Chrome

  • Sarafi

# 测试代码:
----
print('Hello, world')

来自 http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432523496782e0...



讨论 / Python / 总是提示error bad_request, 啥原因?
 返回

总是提示error bad_request, 啥原因?

 问题来源

用户5364760637

#1 Created at 2015-6-22 11:14

看了一下代码,是否某个条件不满足啊?

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"}']


想要问题快速得到解答?分享给朋友试试:

廖雪峰

#2 Created at 2015-6-22 16:20

试试先

print(host, method, path, environ.get('CONTENT_TYPE', ''))

用户5364760637

#3 Created at 2015-6-25 15:29

看了一下,host打印出来是localhost.39093, 不是local.liaoxuefeng.com:3093, 但是local.liaoxuefeng.com:3093 无法运行;所以将代码改了一下HOST = 'localhost:%d' % PORT

在网页上运行,输入print('hello world'), 但是得到结果是:{"output": "hello world\r\n"} 没有弹出网页对话框并显示hello world, 烦请如何破?

廖雪峰

#4 Created at 2015-6-25 16:36

HOST不能改,因为浏览器有CORS限制

'local.liaoxuefeng.com'是指向'127.0.0.1'的,除非dns出问题了

来自 http://www.liaoxuefeng.com/discuss/001409195742008d822b26cf3de46aea14f2b7378a1ba91000/00143494288917...

附件大小
Plain text icon learning.py3.61 KB
普通分类: