General Python #

Last updated March 17, 2026
circuitpython
  • turn an exception into an array of strings with traceback.format_exception(e)
  • format an array of strings into a single string with ”some string”.join(arr)
  • catch an exception:
    try:
        save_pixels('/screenshot.bmp',pixel_source=display)
        logger.info("saved the screenshot")
    except Exception as e:
        logger.error("couldnt take screenshot")
        logger.error(''.join(traceback.format_exception(e)))

  • format a float: print(f”num = {num}”).

  • format a float with leading zeros up to two chars wide: print(f”num = {num:02}”).