我收到以下错误,短划线字符“ - ”
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 38: ordinal not in range(128)
我尝试使用以下:skills.encode('utf-8'),但我仍然得到错误。下面是我试图写入csv的代码。
writer.writerow([name.encode('utf-8'),
heading.encode('utf-8'),
location.encode('utf-8'),
education.encode('utf-8'),
summary,
currentRole,
allRoles,
companiesFollowed,
groups,
skills.encode('utf-8')])
您可以在str.encode
关键字下为errors
指定一些设置。更多信息可以在in the docs找到,但我建议你使用'replace'
错误处理程序。
writer.writerow([name.encode('utf-8', errors='replace'),
heading.encode('utf-8', errors='replace'),
location.encode('utf-8', errors='replace'),
education.encode('utf-8', errors='replace'),
summary,
currentRole,
allRoles,
companiesFollowed,
groups,
skills.encode('utf-8', errors='replace')])
这将最终制作一个bytes
对象,用?
代替每个不可编码的代码点。