Python 3.6 蟒蛇3';ascii';编解码器可以';对1233位置的字节0xc2进行t解码:序号不在范围内(128)

Python 3.6 蟒蛇3';ascii';编解码器可以';对1233位置的字节0xc2进行t解码:序号不在范围内(128),python-3.6,Python 3.6,我正在读python速成班的书。我在用蟒蛇3。 在第16章中,有如下代码: import csv filename = '/Users/pc/Desktop/CS Book/Python_crash_course_practice/16.1/sitka_weather_07-2014.csv' with open(filename) as f: reader = csv.reader(f) header_row = next(reader) print(header_

我正在读python速成班的书。我在用蟒蛇3。 在第16章中,有如下代码:

import csv

filename = '/Users/pc/Desktop/CS 
Book/Python_crash_course_practice/16.1/sitka_weather_07-2014.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)
    print(header_row)
但它不工作,并给了我一个错误如下。我不知道怎么解决它。有人能帮我吗?谢谢

%run -i "/Users/pc/Desktop/CS Book/Python_crash_course_practice/16.1/highs_lows.py"
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
/Users/pc/Desktop/CS Book/Python_crash_course_practice/16.1/highs_lows.py in <module>()
      4 with open(filename) as f:
      5     reader = csv.reader(f)
----> 6     header_row = next(reader)
      7     print(header_row)
      8 
/Users/pc/Library/Enthought/Canopy/edm/envs/User/lib/python3.5/encodings/ascii.py in decode(self, input, final)
     24 class IncrementalDecoder(codecs.IncrementalDecoder):
     25     def decode(self, input, final=False):
---> 26         return codecs.ascii_decode(input, self.errors)[0]
     27 
     28 class StreamWriter(Codec,codecs.StreamWriter):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1233: ordinal not in range(128) 
%run-i”/Users/pc/Desktop/CS Book/Python\u crash\u course\u practice/16.1/highs\u lows.py“
---------------------------------------------------------------------------
UnicodeDecodeError回溯(最近一次呼叫最后一次)
/Users/pc/Desktop/CS Book/Python\u crash\u course\u practice/16.1/highs\u lows.py in()
4打开(文件名)为f时:
5读卡器=csv读卡器(f)
---->6标题行=下一个(读卡器)
7打印(标题行)
8.
/解码中的Users/pc/Library/enthund/Canopy/edm/envs/User/lib/python3.5/encodings/ascii.py(self、input、final)
24类增量编码器(编解码器.增量编码器):
25 def解码(自身、输入、最终=假):
--->26返回编解码器。ascii_解码(输入,自身错误)[0]
27
28类StreamWriter(编解码器、编解码器、StreamWriter):
UnicodeDecodeError:“ascii”编解码器无法解码位置1233处的字节0xc2:序号不在范围内(128)

文件中有非ASCII字符,因此需要在读取时指定文件编码。 您还可以在python脚本的第一行中添加此选项,以将utf-8设置为默认编码

#!/usr/bin/env python # -*- coding: utf-8 -*-

你能解释一下问题到底是什么以及你的答案将如何解决它吗。