Python code for generation of txt file of output - Google Colab
Python code Google Colab for generation of txt file of output.
____________________________
Capturing the output
%%capture output_name (like output_1)
# Python code here
print("This is the output to be saved.")
____________________________
Saving the captured output to a text file
# Specifying the file path
file_path = '/content/output_file_name.txt'
# Saving the captured output to the file
with open(file_path, 'w') as file:
file.write(output_name.stdout)
# Printing a message indicating the file has been saved
print(f"Output saved to: {file_path}")
Comments
Post a Comment