我是 python 新手,在理解 unicode 时遇到问题。我在用着
Python 3.4。
我花了一整天的时间试图通过阅读有关 unicode 的内容来解决这个问题,包括http://www.fileformat.info/info/unicode/char/201C/index.htm http://www.fileformat.info/info/unicode/char/201C/index.htm and
http://python-notes.curiousefficiency.org/en/latest/python3/text_file_processing.html http://python-notes.curiousefficiency.org/en/latest/python3/text_file_processing.html
我需要引用特殊引号,因为它们在我正在分析的文本中使用。我测试过W7命令窗口可以读写2个特殊引号字符。
为了简单起见,我写了一行脚本:
print ('“') # that's the special quote mark in between normal single quotes
并得到这个输出:
Traceback (most recent call last):
File "C:\Users\David\Documents\Python34\Scripts\wordCount3.py", line 1, in <module>
print ('\u201c')
File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u201c' in position 0: character maps to <undefined>
那么我该如何写一些东西来引用这两个角色u201C
and u201D
?
这是文件打开语句中正确的编码选择吗?
with open(fileIn, mode='r', encoding='utf-8', errors='replace') as f: