Newbie: Capture output of compile_dir

Denis S. Otkidach ods at fep.ru
Tue Jul 16 07:05:01 EDT 2002


On Mon, 15 Jul 2002, Becky Hehn wrote:

BH> Thanks for the response.  I tried the code you gave
BH> me, but it didn't quite work like I wanted.  I created
BH> a syntax error in my python file (left out a quotation
BH> mark) and tried the code.  Below is the information
BH> from my interpreter session:
[...]
BH> If an the prompt I just type the compile command, I
BH> get all the output at once(see below).  I would like
BH> the output variable to contain all this feedback from
BH> the compile_dir command.  Not just the initial two
BH> lines.  Any thoughts on what I did wrong?  Thank you
BH> in advance.

Informational messages from compile_dir go to stdout and error
messages go to stderr.  You should redefine both.

orig_so = sys.stdout
orig_se = sys.stderr
sys.stdout = sys.stderr = captured = StringIO()
...

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]
http://diveinto.python.ru/ [ru]







More information about the Python-list mailing list