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

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -