sc_printing#

Printing/notification functions.

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

  • sc.colorize(): print text in a certain color

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

  • sc.sigfig(): truncate a number to a certain number of significant figures

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

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

Classes

prettyobj

Use pretty repr for objects, instead of just showing the type and memory pointer (the Python default for objects).

quickobj

Like sc.prettyobj(), but do not print attribute values.

progressbars

Create multiple progress bars

capture

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

Functions

createcollist

Creates a string for a nice columnated list (e.g. to use in __repr__ method).

objectid

Return the object ID as per the default Python __repr__ method

classatt

Return a sorted string of class attributes for the Python __repr__ method; see sc.prepr() for options

objatt

Return a sorted string of object attributes for the Python __repr__ method; see sc.prepr() for options

objmeth

Return a sorted string of object methods for the Python __repr__ method; see sc.prepr() for options

objprop

Return a sorted string of object properties for the Python __repr__ method; see sc.prepr() for options

objrepr

Print out a detailed representation of an object: methods, properties, attributes, etc.

prepr

Pretty-print a detailed representation of an object.

pr

Pretty-print a detailed representation of an object ("pr" is short for "print repr").

blank

Tiny function to print n blank lines, 3 by default

indent

Small wrapper to make textwrap more user friendly.

sigfig

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

sigfigs

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

arraymean

Quickly calculate the mean and standard deviation of an array.

arraymedian

Quickly calculate the median and confidence interval of an array.

printmean

Alias to sc.arraymean() with doprint=True

printmedian

Alias to sc.arraymedian() with doprint=True

humanize_bytes

Convert a number of bytes into a human-readable total.

printarr

Print a numpy array nicely.

printdata

Nicely print a complicated data structure, a la Matlab.

printvars

Print out a list of variables.

colorize

Colorize output text.

heading

Create a colorful heading.

printred

Alias to print(colors.red(s))

printyellow

Alias to print(colors.yellow(s))

printgreen

Alias to print(colors.green(s))

printcyan

Alias to print(colors.cyan(s))

printblue

Alias to print(colors.blue(s))

printmagenta

Alias to print(colors.magenta(s))

printv

Optionally print a message and automatically indent.

slacknotification

Send a Slack notification when something is finished.

printtologfile

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

percentcomplete

Display progress as a percentage.

progressbar

Show a progress bar for a for loop.