I'm getting an error writing a 'title' line to a csv file:
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
I have a variable called today that I want to use:
today = datetime.today()
today = today.strftime("%m-%d-%Y")
This is the line causing the error:
title_writer = csv.writer(output_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
title_writer.writerow("AWS Master Instance List " + today)
I want the date as represented by the today variable listed next to the title.
How can I do this correctly?
You can fix this with a Find and Replace operation on your code:
Find: tab '\t'
Replace with: four spaces ' '
Having both tabs and spaces will make python unhappy, pick one and stick with it, I suggest spaces.
In fact, depending on what you are using to write your code, you can have this done automatically if you press tab
. In Notepad++ it is under Settings > Preferences > Language > Replace by space
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.