一个漂亮的python打印机。
pprintast的Python项目详细描述
pprintast
一个ast(抽象语法树)漂亮的python打印机。
安装
$ pip install pprintast
用法
usage: pprintast.py [-h] [-a] [-c cmd] [-m mode] [-t] [-v] [file] A pretty-printing dump function for the ast module. The code was copied from the ast.dump function and modified slightly to pretty-print. positional arguments: file program passed in as file optional arguments: -h, --help show this help message and exit -a, --attributes include attributes such as line numbers and column offsets -c cmd, --command cmd program passed in as string -m mode, --mode mode compilation mode (choices: exec, eval, single) (default: exec) -t, --terse terse output by disabling field annotations -v, --version show program's version number and exit
脚本
使用pprintast
cli从文件打印ast。
$ pprintast "./path/to/script.py"
使用pprintast
cli从string打印ast。
$ pprintast -c "lambda a: a**2"
模块
使用pprintast
模块从string打印ast。
# 1. import the "pprintast" function.frompprintastimportpprintastasppast# OR: from pprintast import ppast# 2. pretty print AST from a "string".exp="lambda a: a**2"ppast(exp)
许可证
麻省理工学院Travis Clarke