Python写一个简单的在线编辑器
作者:潘道熹 时间:2022-07-26 22:49:17
直接奔入主题看下面pywebio
程序,实现了Python的简陋在线编辑器
from pywebio.input import *
from pywebio.output import put_text
from os import system,remove
try:
code = textarea('Code Edit Online', code={'mode': "python",'theme': 'darcula'}, value='# input your code here\n')
with open('temp.py','w',encoding = 'utf-8') as f:
f.write(code)
system('python temp.py')
put_text('成功运行程序')
except Exception as e:
put_text('运行:错误 at %s' % e)
主要使用了pywebio
程序,实现了Python的简陋在线编辑器。
相对C++编辑器就比较复杂,需要调用g++.exe,可能在您的电脑上,就不见得能用了,需要把Dev-C++安装到我这个位置,程序才可以运行,您可以修改程序。
from pywebio.input import *
from pywebio.output import put_text
from sys import path
from os import system,remove
try:
system('chcp 65001 >nul')
code = textarea('Code Edit Online ( C++ )', code={'mode': "python",'theme': 'darcula',}, value='// input your code here.\n')
with open('temp.cpp','w',encoding='utf-8') as f:
f.write(code)
put_text('成功运行程序')
system(r'D:\Dev-C++\Dev-cpp\MinGW64\bin\g++.exe "%s\temp.cpp" -o "%s\temp.exe" && call "%s\temp.exe" && pause' % (path[0],path[0],path[0]))
remove('temp.cpp')
remove('temp.exe')
except Exception as e:
put_text('运行:错误 at %s' % e)
运行时会报一个错,不用管它,跟咱们的程序无关。如果不是这个错,那就是您的程序有BUG
。
from pywebio.input import *
from pywebio.output import put_text
from sys import path
from os import system,remove
try:
system('chcp 65001 >nul')
code = textarea('Code Edit Online ( C++ )', code={'mode': "python",'theme': 'darcula',}, value='// input your code here.\n')
with open('temp.cpp','w',encoding='utf-8') as f:
f.write(code)
put_text('成功运行程序')
system(r'D:\Dev-C++\Dev-cpp\MinGW64\bin\g++.exe "%s\temp.cpp" -o "%s\temp.exe" && call "%s\temp.exe" && pause' % (path[0],path[0],path[0]))
remove('temp.cpp')
remove('temp.exe')
except Exception as e:
put_text('运行:错误 at %s' % e)
测试程序,直接运行第一个,输入一段Python代码:
maxNumber = 100
numbers = []
min = 2
numberSum = 0
for i in range(1,101):
numbers.append(i)
while min <= maxNumber:
is_prime = True
for i in range(2,min):
if (min % i) == 0:
is_prime = False
break
if is_prime == True:
numbers.remove(min)
min += 1
print(numbers)
点击蓝色按钮,观察控制台:
成功。
再测C++,测试代码如下(C++:画桃心):
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
for(double y=1.5;y>-1.5;y-=0.1){
for(double x=-1.5;x<1.5;x+=0.05){
double a=x*x+y*y-1;
char b=(a*a*a-x*x*y*y*y<=0.0?'*':' ');
cout<<b;
}
cout<<endl;
}
return 0;
}
输入测试程序并提交,观察控制台:
控制台上多了个大桃心,成功运行。
来源:https://blog.csdn.net/PanDaoxi2020/article/details/122763331
标签:Python,在线,编辑器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python面向对象程序设计类变量与成员变量、类方法与成员方法用法分析
2022-08-11 15:43:43
python3 对list中每个元素进行处理的方法
2022-05-31 13:41:41
Python与人工神经网络:使用神经网络识别手写图像介绍
2022-05-23 03:11:36
![](https://img.aspxhome.com/file/2023/7/86667_0s.png)
Oracle merge合并更新函数实例详解
2023-07-23 02:45:02
Python获取百度热搜的完整代码
2023-09-06 11:33:32
![](https://img.aspxhome.com/file/2023/6/117296_0s.png)
python 寻找离散序列极值点的方法
2021-03-13 15:26:15
jupyter 使用Pillow包显示图像时inline显示方式
2021-09-08 00:42:02
![](https://img.aspxhome.com/file/2023/8/110398_0s.jpg)
在Python中操作字典之update()方法的使用
2023-01-16 09:55:53
巧用CSS滤镜做图案文字
2011-04-29 14:06:00
![](https://img.aspxhome.com/file/UploadPic/20072/2007231136186s.gif)
python中实现php的var_dump函数功能
2023-11-16 07:11:04
![](https://img.aspxhome.com/file/2023/2/101712_0s.jpg)
python中字符串变二维数组的实例讲解
2021-08-03 04:37:56
![](https://img.aspxhome.com/file/2023/5/76885_0s.jpg)
微信小程序之多文件下载的简单封装示例
2023-10-19 21:10:06
Python Pygame实现可控制的烟花游戏
2021-09-08 20:29:02
![](https://img.aspxhome.com/file/2023/4/95214_0s.gif)
通过python实现windows桌面截图代码实例
2023-11-19 03:46:27
php解析xml提示Invalid byte 1 of 1-byte UTF-8 sequence错误的处理方法
2023-09-09 18:55:22
python3中确保枚举值代码分析
2023-05-23 17:47:31
Python Lambda函数使用总结详解
2022-05-07 11:41:31
浅析PEP572: 海象运算符
2023-06-28 10:56:10
Python图像识别+KNN求解数独的实现
2021-06-11 19:48:23
![](https://img.aspxhome.com/file/2023/6/130946_0s.png)
HTML5中 b 和 i 标签将语义化
2008-03-16 13:43:00