IndexError: Replacement index 1 out of range for positional args tuple

from datetime import datetime
with pd.ExcelWriter('./output/{}_sample_{}.xlsx'.format(re.split('[\\\, .]', file)[-2]), datetime.now().strftime('%m%d_%H%M')) as writer:
    df_LS_ALL.to_excel(writer, sheet_name='sheet1')  
    df_Par.to_excel(writer, sheet_name='sheet2')  
writer.save()
writer.close()

报错如下:
File "", line 2, in

'./output/{}_sample_{}.xlsx'.format(re.split('[\\\, .]', file)[-2]), datetime.now().strftime('%m%d_%H%M')) as writer:

IndexError: Replacement index 1 out of range for positional args tuple

括号写错了,正确代码如下:

from datetime import datetime
with pd.ExcelWriter('./output/{}_sample_{}.xlsx'.format(re.split('[\\\, .]', file)[-2], datetime.now().strftime('%m%d_%H%M'))) as writer:
    df_LS_ALL.to_excel(writer, sheet_name='sheet1')  
    df_Par.to_excel(writer, sheet_name='sheet2')  
writer.save()
writer.close()

你可能感兴趣的:(bug,python,excel,开发语言)