I am iterating over a list of words
(which I didn't generate)
print(u'\n'.join('{}:{}'.format(w, f) for f,w in words))
I get the error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 0: ordinal not in range(128)
The non problematic words are getting printed as expected. How can I fix this print statement?
使用.encode()方法:
print(u'\n'.join('{}:{}'.format(w.encode('utf-8'), f).decode('utf-8') for f,w in words))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.