I'd like to use prettyprint to print out a dictionary, but into a string and not to console. This string is to be passed on to other functions.
I know I can use the "stream" parameter to specify a file instead of sys.out but I want a string.
How do I do that?
Just use the StringIO module:
StringIO
import StringIO output = StringIO.StringIO()
Now you may pass output as a stream to prettyprint.
output
prettyprint
2.1m questions
2.1m answers
60 comments
57.0k users