redirect output of functions to a string or file 
Author Message
 redirect output of functions to a string or file

Hi!

    I have several functions that return strings.  The output of these
functions must be combined and saved into a file.

    Is there a way to tell python to "automagically" redirect the output
of _all_ functions to a string or file? O:-)

TIA
---------------------------------------
Fernando Rodrguez



Fri, 27 Dec 2002 03:00:00 GMT  
 redirect output of functions to a string or file

Quote:

>     Is there a way to tell Python to "automagically" redirect the output
> of _all_ functions to a string or file? O:-)

You can redirect standard output:

import sys
sys.stdout = open("somefile.output","w")

then you can just print the result of the functions.

hope that helps - if not, send code or wait for better replies,
Peter
--
Peter Schneider-Kamp          ++47-7388-7331

N-7050 Trondheim              http://schneider-kamp.de



Fri, 27 Dec 2002 03:00:00 GMT  
 redirect output of functions to a string or file

Quote:
> Hi!

>     I have several functions that return strings.  The output of these
> functions must be combined and saved into a file.

>     Is there a way to tell Python to "automagically" redirect the output
> of _all_ functions to a string or file? O:-)

Redirect?  So that, for example:
    a=f()
would NOT actually set a, but rather (leave it as before? or what
else?) and instead place f()'s return value somewhere else?  That
seems like a tall order to me, and I don't understand how it would
help -- surely you're using the value of a in later code, so if it does
not get set this will affect your code's logic...?

Alex



Sat, 28 Dec 2002 03:00:00 GMT  
 redirect output of functions to a string or file
Sounds like you're looking for some tracing functionality to help you debug?

I don't think you would want ALL functions to display their output to a
file, since you may find that file grows really, really quick!

You may just want to add a "print" at the end of functions that you want to
debug, or use some class that doesn't do anything in "retail" mode, but in
"debug" mode, will print all output in a window or out to a file....

--
----------------------------------------------------------------------
Olivier A. Dagenais - Carleton University - Computer Science III


Quote:
> Hi!

>     I have several functions that return strings.  The output of these
> functions must be combined and saved into a file.

>     Is there a way to tell Python to "automagically" redirect the output
> of _all_ functions to a string or file? O:-)

> TIA
> ---------------------------------------
> Fernando Rodrguez



Sun, 29 Dec 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Redirecting Output to files

2. Redirecting to TWO output files

3. Redirecting program output to file

4. how to redirect lpt1 to file-output

5. redirect g77 output into a file under windows xp

6. Redirect file output into variables

7. redirect g77 under DOS 6.22- need output file

8. expect: redirect output into file called `uname -n'.txt

9. redirect exec output to a file

10. Redirecting output to a scratch file

11. Redirecting output to file with elisp

12. Redirecting TCL script output to a file

 

 
Powered by phpBB® Forum Software