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 - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -