How to write a list to a text file exactly as it appears in python? -
i want able write list text file, appear if print out in console (with brackets , everything). reason being, need use list later on , has appear if being printed.
i've tried using csv module, couldn't formatted wanted.
any suggestions?
try using repr
. repr "returns canonical string representation of object", should give same string gets printed when inspect things on interactive prompt.
file.write(repr(my_list))
Comments
Post a Comment