Capturing stdout within the same process in Python

Posted by danben on Stack Overflow See other posts from Stack Overflow or by danben
Published on 2010-04-16T17:04:49Z Indexed on 2010/04/16 17:13 UTC
Read the original article Hit count: 245

Filed under:
|
|

I've got a python script that calls a bunch of functions, each of which writes output to stdout. Sometimes when I run it, I'd like to send the output in an e-mail (along with a generated file). I'd like to know how I can capture the output in memory so I can use the email module to build the e-mail.

My ideas so far were:

  • use a memory-mapped file (but it seems like I have to reserve space on disk for this, and I don't know how long the output will be)
  • bypass all this and pipe the output to sendmail (but this may be difficult if I also want to attach the file)

© Stack Overflow or respective owner

Related posts about python

Related posts about output