Python: write a list with non-ASCII characters to a text file

前端 未结 4 2009
遥遥无期
遥遥无期 2021-02-08 15:22

I\'m using python 3.4 and I\'m trying to write a list of names to a text file. The list is as follows:

my_list = [\'Dejan Živković\',\'Gregg Berhalter\',\'James          


        
4条回答
  •  無奈伤痛
    2021-02-08 15:51

    try this:

    >>> my_list = ['Dejan Živković','Gregg Berhalter','James Stevens','Mike Windischmann' ,'Gunnar Heiðar Þorvaldsson']
    >>> f = open("/Users/.../Desktop/Name_Python.txt", "w")
    >>> for x in my_list:
    ...     f.write("{}\n".format(x))
    ... 
    >>> f.close()
    

提交回复
热议问题