Saving The Output Of A Cell In Jupyter Notebook With A New Line After Each Number
I saved output of a cell as a txt file as follows: First cell: %%capture cap --no-stderr print(q) Second cell: with open('output.txt', 'w') as f: f.write(cap.stdout) Below is
Solution 1:
%%capture
capture all the out of the code beside it in this cell, so you can print out all the elements from the list.
%%capture cap --no-stderr
for i in q:
print(i)
with open('output.txt', 'w') as f:
f.write(cap.stdout)
cap.stdout
handle what %%capture
captured as a whole, so when you tried to add \n
, it won't work.
Is it what you want?
Post a Comment for "Saving The Output Of A Cell In Jupyter Notebook With A New Line After Each Number"