log
2023-06-13
新标准
新特性
Python 使用 attrs 和 cattrs 实现面向对象编程
Python Prompt Toolkit 3.0 | Tutorial: Build an SQLite REPL
语法高亮 支持多行编辑 支持代码补全 支持自动提示 使用鼠标移动光标 支持查询历史 对 Unicode 支持良好 跨平台 支持 Emacs 与 Vi 风格的快捷键 PromptSession 不用在循环中多次定义prompt特牲 根据历史输入文件自动输入内容 from __future__ import print_function from __future__ import unicode_literals from prompt_toolkit import prompt from prompt_toolkit.history import FileHistory from prompt_toolkit.auto_suggest import AutoSuggestFromHistory while True: user_input = prompt('>>>', history=FileHistory('history.txt'), auto_suggest=AutoSuggestFromHistory()) if user_input.strip().lower() == 'exit': break print(user_input)
pygments
pygments是一个代码格式化库,可以将代码格式化为html,图片和rtf文件等多种格式 from pygments import highlight from pygments.lexers import PythonLexer from pygments.formatters import HtmlFormatter code = 'print "Hello World"' print(highlight(code, PythonLexer(), HtmlFormatter())) 输出: <div class="highlight"> <pre><span class="k">print</span> <span class="s">"Hello World"</span></pre> </div> 命令行: pygmentize -f html -o test.html test.py