Skip to main content

Indents and pretty prints data structures

Project description

iformat

iformat is a simple package that prints basic data structures in an indented and readable way. The main iprint function supports changing the indent size and expansion threshold, as well as all vanilla print arguments. The included iformat function provides more customization, and returns a string that has been indented and formatted. An .iformat method (returning a string) can be added to any class for that class to be printed with custom formatting, and classes are otherwise printed with all their methods.

Parameters:

indentDepth: (iprint and iformat)
Specifies how many spaces should be inserted as one indent level. Default 4.

expansionThreshold: (iprint and iformat)
Specifies how long an object must be when printed before it is shown in a muilti-line format. Default 0.
Ex:

iprint([1, 2, 3], expansionThreshold = 10)
# [1, 2, 3]

iprint([1, 2, 3], expansionThreshold = 0)
# [
#   1,
#   2,
#   3
# ]

excludedAttrs: (iprint and iformat)
Specifies class attributes that should not be printed. Should be a list or tuple of strings OR a regex pattern. Default r"__.+__".

.iformat method for classes:

You can add a .iformat method to any class to show the return value of that method instead of the default iformat output for classes. It must accept positional arguments indentLevel, indentDepth, expansionThreshold, and excludedAttrs, which will be passed the same values as those passed to the iformat function call that calls the method. It is reccomended that you add whitespace in front of the output corresponding to indentLevel * indentDepth, and that you call iformat, with the same passed args (maybe with indentDepth + 1) on any values that are part of the outputted string.

indentLevel: (iformat only)
Specifies the indent level of the returned output string. Default 0.

https://github.com/FinnE145/iprint

https://pypi.org/project/iformat

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iformat-0.3.3.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

iformat-0.3.3-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file iformat-0.3.3.tar.gz.

File metadata

  • Download URL: iformat-0.3.3.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for iformat-0.3.3.tar.gz
Algorithm Hash digest
SHA256 c4eca8ed439671082dd51847e63d645483d2f24ca9772c18d620d8bcd5d1e3d2
MD5 02586d6c69c9ee58e62e93e2f34fa681
BLAKE2b-256 3428934f44894ee095fe8a3dbe89b2c4a4b7f05b51bbd2acc5dd25390dcd2720

See more details on using hashes here.

File details

Details for the file iformat-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: iformat-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for iformat-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 164017513f8e1e637af7df59cb977ae0946715ad6d03656ee4c1d2e399eeb527
MD5 480780d19617f3be085b7d74243ef652
BLAKE2b-256 396deca909dd287d533c5a0340362985dbbde1db020d213abbb063cf2ee80ccc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page