Home > Blockchain >  Saving output in txt file
Saving output in txt file

Time:01-06

I have a python program that gives 3000 outputs in five seconds, and it gives millions of outputs in minutes. So I wanna know how to save the outputs in a '.txt' file automatically.

I think I need a python program to save all my outputs in a .txt file. I use python 2 for some reason.

The problem I have is,

  • windows does not have unlimited scrollback.
  • I don't have ubuntu.
  • If I try to copy my outputs my system hangs cuz it has just 4gb ram.

Help me guys, Thanks in advance.

CodePudding user response:

By output I am assuming you are talking about print() statements. You can redirect your standard output to have print() go to a file instead:

import sys

with open('output.txt','w') as f:
    sys.stdout = f
    print('Hello')

CodePudding user response:

Add this piece of code before you start outputting:

f = open(“file.txt”, “w ”)

Add this piece of code during outputting:

f.write(outputvar)

Add this piece of code after outputting:

f.close()

I hope this helps, if it doesn’t, please tell me.

  •  Tags:  
  • Related