I saved output of a cell as a txt file as follows:
First cell:
%%capture cap --no-stderr
print(q)
Second cell:
with ope
%%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?