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

前端 未结 4 1997
遥遥无期
遥遥无期 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 16:09

    Best method would be to play with unicodes

    my_list = [u'Dejan \u017Divkovi\u0107','Gregg Berhalter','James Stevens','Mike Windischmann'
               ,u'Gunnar Hei\u00F0ar \u00FEorvaldsson']
    print my_list[0]
    

    Output:Dejan Živković

提交回复
热议问题