flexstr#

flexstr(arg, *args, force=True, join='')[source]#

Try converting any object to a “regular” string (i.e. str), but proceed if it fails. Note: this function calls repr() rather than str() to ensure a more robust representation of objects.

Parameters:
  • arg (any) – the object to convert to a string

  • args (list) – additional arguments

  • force (bool) – whether to force it to be a string

  • join (str) – if multiple arguments are provided, the character to use to join

Example:

sc.flexstr(b'foo', 'bar', [1,2]) # Returns 'foobar[1, 2]'

New in version 3.0.0: handle multiple inputs