Issue
In Google Colab, I want to execute several lines of python code, both print and function. The goal is to redirect the result to a file.Any tips?
Solution
- In the cell do you want to print to the file write the following:
%%capture cap
- For print into a file:
f = open("output.txt", "w")
print(cap, file=f)
f.close()
- Note: With very large outputs it may not work very well.
The object type of variable
c
is CapturedIO from IPython.utils.capture
Answered By - Rafael Lourenço
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.