Is this the cleanest way to write a list to a file, since writelines() doesn\'t insert newline characters?
writelines()
file.writelines([\"%s\\n\" % item fo
Redirecting stdout to a file might also be useful for this purpose:
from contextlib import redirect_stdout with open('test.txt', 'w') as f: with redirect_stdout(f): for i in range(mylst.size): print(mylst[i])