PrettyPrint python into a string, and not stdout August 4, 2023 by Tarik You should simply call the pformat function from the pprint module: import pprint s = pprint.pformat(aDict)