Python Forum
Loops - new terminal output to file for each loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loops - new terminal output to file for each loop
#1
Hi all!

So I'm a beginner and teaching myself! I am running a scientific model, the main code to which is beyond me(!) and installed on my computer. I have some 'instruction' code which I run to tell the model which variables and options I want to use. When I run this code, I get a series of output files in the current working directory which are products of the scientific model, alongside the large output in the terminal, which I am currently saving to a file using &> terminal_output &

I now want to run the model multiple times for multiple combinations of different variables. To do this I am putting the 'instruction' code in a series of nested for loops. However I want to get the equivalent of the terminal output into a new file for each loop. So for each loop I will have a new file containing the terminal output just for that run over the loops. I hope that makes sense...

Any help would be much appreciated! Thanks!
Reply
#2
It would depend on how the program you are using is structured and how you are calling it. If it is just a few print statements in a function, I would use the file parameter of the print statements to redirect the output, passing it to the print statements by adding a parameter to the function you are calling. If that is not feasible, I would redirect sys.stdout, which would send all print statements to a specified file.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,088 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,075 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,566 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  For loops returning wrong output Nighthound21 1 1,955 May-03-2021, 03:43 AM
Last Post: deanhystad
  using 'while loop' output going into infinite loop... amitkb 2 1,942 Oct-05-2020, 09:18 PM
Last Post: micseydel
  Output CSV file with filepath and file contents glittergirl 1 1,747 Aug-03-2020, 01:50 AM
Last Post: glittergirl
  sports Stats > table output loop problems paulfearn100 3 2,487 Jul-22-2020, 03:21 AM
Last Post: c_rutherford
  Print output in single file using pramika loop deepakkhw 1 2,064 Jul-11-2020, 11:57 AM
Last Post: j.crater
  print result in OUTPUT not in TERMINAL picasso 1 2,051 Apr-15-2020, 03:51 PM
Last Post: deanhystad
  csv file output rturus 7 3,216 Jan-30-2020, 02:09 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020