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?
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()
c is CapturedIO from IPython.utils.captureIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With