Redirecting STDOUT to a Python Variable

Paul Rubin no.email at nospam.invalid
Tue Jun 22 02:30:32 EDT 2010


Anthony Papillion <papillion at gmail.com> writes:
> I'm writing an application that uses the Google Storage Python
> library.  When an error occurs, the error is printed on the terminal.
> What I need to do is intercept that text into a variable so I can run
> a re.search() against it and find out what's going on.

I'm unfamiliar with that library, but if you mean it raises an
exception, the thing to do is catch the exception and examine the
response code that it should supply.  Actually parsing the text error
message is horrendous (think of internationalization, for example).
Though it is sometimes necessary, if the code throwing the exception is
well designed, it shouldn't require parsing the text.

See the python docs about the try/except statement to learn about
exceptions in Python.



More information about the Python-list mailing list