prepr#

prepr(obj, vals=True, maxlen=None, maxitems=None, skip=None, dividerchar='—', dividerlen=72, use_repr=True, private=False, sort=True, strlen=22, ncol=3, maxtime=3, maxrecurse=5, die=False, debug=False)[source]#

Pretty-print a detailed representation of an object.

This function returns a pretty (and pretty detailed) representation of an object – all attributes (except any that are skipped), plus methods and ID.

This function is usually used via the interactive sc.pr() (which prints), rather than this function (which returns a string).

Parameters:
  • obj (anything) – the object to be represented

  • vals (bool) – whether to show attribute values (else, just list attributes; similar to sc.objrepr())

  • maxlen (int) – maximum number of characters to show for each attribute

  • maxitems (int) – maximum number of attribute to show in the object

  • skip (list) – any attributes to skip

  • dividerchar (str) – divider for methods, attributes, etc.

  • dividerlen (int) – number of divider characters

  • use_repr (bool) – whether to use repr() or str() to parse the object

  • private (bool) – whether to include private methods/attributes (those starting with “__”)

  • maxtime (float) – maximum amount of time (in seconds) to spend on trying to print the object

  • maxrecurse (int) – maximum number of levels to descend in the object (set to 0 to turn off the check)

  • die (bool) – whether to raise an exception if an error is encountered

  • debug (bool) – print out detail during string construction

New in version 3.0.0: “debug” argument
New in version 3.1.4: more robust handling of invalid object properties
New in version 3.1.5: “vals” argument to turn off printing attribute values
New in version 3.1.6: “maxrecurse” argument, and checking for recursion

Examples:

# Default options
df = sc.dataframe(a=[1,2,3], b=[4,5,6])
print(df) # See just the data
sc.pr(df) # See all the methods too
sc.pr(df, vals=False) # Only see methods, not the values

# Demonstrate options
obj = sc.prettyobj({k:k for k in [l + str(n) for n in range(10) for l in 'abcde']}) # Big object
sc.pr(obj, maxitems=20, sort=False, dividerchar='•', dividerlen=43, private=True)