Save a list to a .txt file

后端 未结 3 790
不思量自难忘°
不思量自难忘° 2020-12-14 02:11

Is there a function in python that allows us to save a list in a txt file and keep its format?

If I have the list:

values = [\'1\',\'2\',\'3\']
         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 02:49

    Try this, if it helps you

    values = ['1', '2', '3']
    
    with open("file.txt", "w") as output:
        output.write(str(values))
    

提交回复
热议问题