sciris.sc_printing

Printing/notification functions.

Highlights:
  • heading(): print text as a ‘large’ heading

  • colorize(): print text in a certain color

  • pr(): print full representation of an object, including methods and each attribute

  • sigfigs(): truncate a number to a certain number of significant figures

  • progressbar(): show a (text-based) progress bar

  • capture(): capture text output (e.g., stdout) as a variable

Functions

blank

Tiny function to print n blank lines, 3 by default

colorize

Colorize output text.

createcollist

Creates a string for a nice columnated list (e.g.

heading

Create a colorful heading.

indent

Small wrapper to make textwrap more user friendly.

objatt

Return a sorted string of object attributes for the Python __repr__ method

objectid

Return the object ID as per the default Python __repr__ method

objmeth

Return a sorted string of object methods for the Python __repr__ method

objprop

Return a sorted string of object properties for the Python __repr__ method

objrepr

Return useful printout for the Python __repr__ method

percentcomplete

Display progress.

pr

Shortcut for printing the pretty repr for an object -- similar to prettyprint

prepr

Akin to "pretty print", returns a pretty representation of an object -- all attributes (except any that are skipped), plust methods and ID.

printarr

Print a numpy array nicely.

printblue

Alias to print(colors.blue(s))

printcyan

Alias to print(colors.cyan(s))

printdata

Nicely print a complicated data structure, a la Matlab.

printgreen

Alias to print(colors.green(s))

printmagenta

Alias to print(colors.magenta(s))

printred

Alias to print(colors.red(s))

printtologfile

Append a message string to a file specified by a filename name/path.

printv

Optionally print a message and automatically indent.

printvars

Print out a list of variables.

printyellow

Alias to print(colors.yellow(s))

progressbar

Call in a loop to create terminal progress bar.

sigfig

Return a string representation of variable x with sigfigs number of significant figures

slacknotification

Send a Slack notification when something is finished.

Classes

capture

Captures stdout (e.g., from print()) as a variable.