pprintastΒΆ

Version 1.2.1

https://img.shields.io/pypi/v/pprintast.svg https://img.shields.io/pypi/pyversions/pprintast.svg https://pepy.tech/badge/pprintast

An AST (abstract syntax tree) pretty printer for Python 🐍.

InstallationΒΆ

$ pip install pprintast

UsageΒΆ

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

ScriptΒΆ

Pretty print AST from a file using the pprintast CLI.

$ pprintast "./path/to/script.py"

Pretty print AST from a string using the pprintast CLI.

$ pprintast -c "lambda a: a**2"

ModuleΒΆ

Pretty print AST from a string using the pprintast module.


# 1. import the "pprintast" function.
from pprintast import pprintast as ppast # OR: from pprintast import ppast

# 2. pretty print AST from a "string".
exp = "lambda a: a**2"

ppast(exp)

stdout

LicenseΒΆ

MIT Β© Travis Clarke