python3 在线工具 菜鸟工具_菜鸟工具(https://c.runoob.com/)桌面版

\nusing namespace std;\n\nint main() {\n\tcout << "Hello C++";\n\treturn 0;\n}'), ('C', 7, '#include

\n\nint main() {\n\tprintf("Hello C!");\n\treturn 0;\n}'), ('Java', 8, 'public class HelloWorld {\n\tpublic static void main(String []args) {\n\t\tSystem.out.println("Hello Java!");\n\t}\n}'), ('Python 3', 15, 'print("Hello Python 3!")'), ('Python', 0, 'print "Hello Python!"'), ('PHP', 3, '

') ) def __init__(self, parent): super().__init__(parent) self.addItems(['{} 在线工具'.format(language[0]) for language in self.languages]) @property def language(self): return self.languages[self.currentIndex()][1] @property def code(self): return self.languages[self.currentIndex()][2] class Editor(QPlainTextEdit): def __init__(self, parent, placeholder): super().__init__(parent) self.setPlaceholderText(placeholder) self.setTabStopWidth(28) def loadScriptFile(self, filename): try: with open(filename, 'r', encoding=sys.getdefaultencoding()) as f: code = f.read() except Exception as err: code = 'File Error: {}'.format(err) self.setPlainText(code) def dragEnterEvent(self, event): super().dragEnterEvent(event) if event.mimeData().hasUrls(): event.accept() else: event.ignore() def dropEvent(self, event): super().dropEvent(event) if event.mimeData().hasUrls(): self.loadScriptFile(event.mimeData().text()[8:]) else: event.ignore() def mouseDoubleClickEvent(self, event): super().mouseDoubleClickEvent(event) self.loadScriptFile(QFileDialog.getOpenFileName(self, '选择密码提示文件')[0]) class Console(QTextBrowser): def __init__(self, parent, placeholder): super().__init__(parent) self.setPlaceholderText(placeholder) def enterEvent(self, event): super().enterEvent(event) self.resize(400, 400) def leaveEvent(self, event): super().leaveEvent(event) self.resize(400, 30) class Layout(QWidget): def __init__(self): super().__init__() self.setWindowTitle('在线代码运行器') self.setFixedSize(800, 600) self.setWindowIcon(QApplication.style().standardIcon(QStyle.SP_TitleBarMenuButton)) self.setStyleSheet('font-family: "Microsoft Yahei"; font-size: 14px;') self.button_compile = QPushButton('运 行', self) self.button_compile.setGeometry(QRect(20, 20, 80, 30)) self.button_clear = QPushButton('清 空', self) self.button_clear.setGeometry(QRect(110, 20, 80, 30)) self.combobox = ComboBox(self) self.combobox.setGeometry(QRect(200, 20, 170, 30)) self.editor = Editor(self, '双击加载代码文件或拖动文件到这里……') self.editor.setGeometry(QRect(20, 60, 760, 520)) self.editor.setStyleSheet('font-family: "sans-serif";') self.console = Console(self, '运行结果……') self.console.setGeometry(QRect(380, 20, 400, 30)) class Program(Layout): def __init__(self): super().__init__() self.compiler = Compiler() self.button_compile.clicked.connect(self.execute) self.button_clear.clicked.connect(self.clear) self.combobox.currentIndexChanged.connect(self.select) self.compiler.compiled.connect(self.receive) self.editor.setPlainText(self.combobox.code) def select(self): self.compiler.blocked = True self.editor.setPlainText(self.combobox.code) def execute(self): self.compiler.blocked = True self.compiler.preprocess(self.editor.toPlainText(), self.combobox.language) self.console.setText('程序正在运行中……') def clear(self): self.compiler.blocked = True self.editor.setPlainText('') self.console.setText('') def receive(self, result): self.console.setText(result) if __name__ == '__main__': app = QApplication(sys.argv) program = Program() program.show() sys.exit(app.exec())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要爬取 https://www.runoob.com/manual/pythontutorial/docs/html/ 中的一段文本,可以使用 Python 的 requests 库和 BeautifulSoup 库。 以下是一个示例代码,用于爬取 Python 教程中第一篇文章的第一段内容: ```python import requests from bs4 import BeautifulSoup url = 'https://www.runoob.com/manual/pythontutorial/docs/html/python-beginner.html' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') content = soup.find('div', class_='article-intro').p.text.strip() print(content) ``` 首先,使用 requests 库获取 Python 教程的第一篇文章的页面内容,并将其存储在变量 response 中。 接着,使用 BeautifulSoup 库解析页面内容,并使用 `soup.find()` 方法找到页面中的 class 为 `article-intro` 的 div 元素,然后再从这个 div 元素中找到第一个 p 标签元素。 最后,使用 `text` 属性获取 p 标签元素的文本内容,并使用 `strip()` 方法去除文本内容前后的空格和换行符。 执行上述代码,输出第一篇文章的第一段内容: ``` Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。Python 由 Guido van Rossum 于 1989 年底发明,第一个公开发行版发行于 1991 年。Python 语法简洁而清晰,具有丰富和强大的类库。它常被称为胶水语言,能够把用其他语言制作的各种模块(尤其是 C/C++)很轻松地联结在一起。Python 适用于大多数平台,包括 Windows、Linux、Unix、Mac OS X 等,并且有许多第三方库可以帮助我们进行各种操作。 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值