0

I'm a bit confused on how redirecting python output works.

For example, if I run my python code with any file, let's say "file.input," my code uses this file to do some calculations, but then I want my output to be sent to the screen, but also to a corresponding "file.output."

Example "calculations.input" contains the formula c= a+b, then in my code I say that a=1, b=2, but now I want this output printed to the screen, and into a corresponding "calculations.output" file. Any ideas, as I'm using Windows please?

So if the first time i run the code, i run it with example.input (and expect an example.out file to be automatically created), then the next time i run it with example2.input (with example2.output being created)

Dave
  • 1
  • 1
  • related: [How do I duplicate sys.stdout to a log file in python?](http://stackoverflow.com/a/616686/4279) – jfs Sep 13 '15 at 18:32
  • thanks, but what if I don't know the name of my input file? – Dave Sep 13 '15 at 18:42
  • don't put the info necessary to answer your question in the comments: [edit] your question instead. What does it mean *"don't know the name of the file"*? – jfs Sep 13 '15 at 18:46
  • sorry. I meant it the first time i run the code, i run it with example.input (and expect an example.out file to be automatically created), then the next time i run it with example2.input (with example2.output being created) – Dave Sep 13 '15 at 18:56
  • If you don't know how to create `"example2.output"` string if you are given `"example2.input"` string e.g., via command-line (`sys.argv` list) then ask a separate question. It is unrelated to redirecting. – jfs Sep 13 '15 at 19:01

0 Answers0