iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python写一个简单的在线编辑器
  • 110
分享到

Python写一个简单的在线编辑器

2024-04-02 19:04:59 110人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

直接奔入主题看下面pyWEBio程序,实现了python的简陋在线编辑器 from pywebio.input import * from pywebio.output import

直接奔入主题看下面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;
}

输入测试程序并提交,观察控制台:

控制台上多了个大桃心,成功运行。

到此这篇关于Python写一个简单的在线编辑器的文章就介绍到这了,更多相关Python写线编辑器内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Python写一个简单的在线编辑器

本文链接: https://www.lsjlt.com/news/138189.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作