Redirect print in Python: val = print(arg) to output mixed iterable to file

Posted by emcee on Stack Overflow See other posts from Stack Overflow or by emcee
Published on 2010-03-19T11:51:48Z Indexed on 2010/03/19 12:11 UTC
Read the original article Hit count: 294

Filed under:
|
|
|

So lets say I have an incredibly nested iterable of lists/dictionaries. I would like to print them to a file as easily as possible. Why can't I just redirect print to a file?

val = print(arg) gets a SyntaxError.

Is there a way to access stdinput?

And why does print take forever with massive strings? Bad programming on my side for outputting massive strings, but quick debugging--and isn't that leveraging the strength of an interactive prompt?

There's probably also an easier way than my gripe. Has the hive-mind an answer?

© Stack Overflow or respective owner

Related posts about python

Related posts about iterable