简体   繁体   English

Python:UnicodeEncodeError:'ascii'编解码器无法在位置0编码字符u'\\ xfc':序数不在范围内(128)-> Excel

[英]Python: UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 0: ordinal not in range(128) -> Excel

I am trying to wrap my head around this for a while now and have not yet seen any solution that does not confuse me. 我正在努力解决这个问题,并且还没有看到任何可以使我感到困惑的解决方案。

I got a script in python that should write an array with words (German Names) into an excel file. 我在python中获得了一个脚本,该脚本应将带有单词(德语名称)的数组写入excel文件。

cell = [name_1, name_2, name_3]   

import csv
 fl = open('company_data.csv', 'w')

 writer = csv.writer(fl)
 writer.writerow(['Name_1', 'Name_2', 'Name_3']) 
 for values in cell:
     writer.writerow(values)

 fl.close() 

The error that comes is ...,line 135, in writer.writerow(values) UnicodeEncodeError: 'ascii' codec can't encode character u'\\xfc' in position 0: ordinal not in range(128) [Finished in 1.2s with exit code 1] 出现的错误是...,第135行,在writer.writerow(values)中UnicodeEncodeError:'ascii'编解码器无法在位置0编码字符u'\\ xfc':序数不在range(128)中[在1.2中完成s,退出代码为1]

The names include the German characters ü,ä,ö etc. 名称包括德语字符ü,ä,ö等。

How do I fix this? 我该如何解决?

I think you have to open the file and specify that you want to write unicode. 我认为您必须打开文件并指定要编写unicode。 Aussming you want utf-8: 说明您要utf-8:

import codecs
fl = codecs.open("company_data.csv", "w", "utf-8")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python:UnicodeEncodeError:'ascii'编解码器无法编码位置78中的字符u'\\ xf1':序数不在范围内(128) - Python: UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 78: ordinal not in range(128) Python:UnicodeEncodeError:'ascii' 编解码器无法在位置 0 中对字符 '\Ο' 进行编码:序号不在范围内 (128) - Python: UnicodeEncodeError: 'ascii' codec can't encode character '\u039f' in position 0: ordinal not in range(128) UnicodeEncodeError:'ascii'编解码器无法在位置1处编码字符u'\\ u2730':序数不在范围内(128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\u2730' in position 1: ordinal not in range(128) UnicodeEncodeError: 'ascii' codec can't encode character u'\’' in position 6: ordinal not in range(128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 6: ordinal not in range(128) UnicodeEncodeError:'ascii'编解码器无法对位置126中的字符u'\\ u2019'进行编码:序数不在范围内(128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 126: ordinal not in range(128) UnicodeEncodeError:'ascii'编解码器无法对位置34中的字符u'\\ u05a0'进行编码:序数不在范围内(128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\u05a0' in position 34: ordinal not in range(128) UnicodeEncodeError:'ascii'编解码器无法对位置47中的字符u'\\ u2019'进行编码:序数不在范围内(128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 47: ordinal not in range(128) UnicodeEncodeError: 'ascii' codec can't encode character u'\ц' in position 32: ordinal not in range(128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\u0446' in position 32: ordinal not in range(128) UnicodeEncodeError:'ascii'编解码器无法在位置30339编码字符u'\\ u2019':序数不在范围内(128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 30339: ordinal not in range(128) UnicodeEncodeError: 'ascii' 编解码器无法对位置 0 中的字符 u'\ا' 进行编码:序号不在范围内 (128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\u0627' in position 0: ordinal not in range(128)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM