Python异常处理:IndentationError: unexpected indent

示例代码:

"""
Author:  yeahthon
Date   :  2019-08-11  17:16:27
E-mail:  [email protected]
"""

import  csv

fill_name = 'sitka_weather_2014.csv'
with  open(fill_name) as  f:
    reader = csv.reader(f)
    header_row = next(reader)
     for  index, column_header in  enumerate(header_row):
         print(index, column_header)

异常提示:

G:\python\practice\pycharm\venv\Scripts\python.exe G:/python/pycharm/2019081101/highs_lows.py
  File "G:/python/pycharm/2019081101/highs_lows.py", line 13
    for  index, column_header in  enumerate(header_row):
    ^
IndentationError: unexpected indent

Process finished with exit code 1

异常分析:IndentationError 即缩进错误,python根据缩进来判断代码行与前一个代码行的关系,每行开头多余的空格会导致意想不到的缩进,从而影响整个代码段的相互关系,导致程序错误。
异常处理:删除代码段第13行部分空格,使for语句与上一行代码对其,并列属于whth语句下即可。正确 规范代码段缩进,使其结构清晰整洁。

你可能感兴趣的:(python)