在将“ title”行写入csv文件时遇到错误:
File ".\aws_ec2_list_instances.py", line 58
title_writer.writerow("AWS Master Instance List " + today)
^
TabError: inconsistent use of tabs and spaces in indentation
我有一个今天要使用的变量:
today = datetime.today()
today = today.strftime("%m-%d-%Y")
这是导致错误的行:
title_writer = csv.writer(output_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
title_writer.writerow("AWS Master Instance List " + today)
我想要标题旁边列出的Today变量表示的日期。
如何正确执行此操作?
答案 0 :(得分:2)
您可以通过对代码进行查找和替换操作来解决此问题:
Find: tab '\t'
Replace with: four spaces ' '
同时使用制表符和空格会使python感到不高兴,请选择其中一个并坚持使用,我建议使用空格。
实际上,如果您按tab
,则可以自动完成此操作,具体取决于编写代码的方式。在Notepad ++中,它位于设置>首选项>语言>用空格替换