用Python将数据转换为日期格式,但未缩进与任何外部缩进级别不匹配。

3

i have below python Code

def add_value_by_date(file_name, start_column, start_row, value):
    with closing(load_workbook(filename=file_name)) as wb:
    ws = wb.active
    start_row =int(start_row)
    start_column= int(start_column)
    for i in value:
        i = datetime.datetime.strptime(i, "%m/%d/%Y")
        ws.cell(row=start_row, column=start_column).value = i
        start_row += 1
    wb.save(file_name)

在尝试转换值 i = datetime.datetime.strptime(i, "%m/%d/%Y") 后,我遇到了错误。

我的列表中的数据:

['06/26/2018', '06/26/2018']

错误消息:

IndentationError: unindent does not match any outer indentation level

1个回答

4

您的代码存在语法错误。

具体来说,

with closing(load_workbook(filename=file_name)) as wb:
ws = wb.active
...
< p >在with语句下面的代码块应该缩进!< /p >

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接