Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Append inside for?
#2
There is no error in the posted code. The error message indicates that sometimes you indent using tabs and other times using spaces. I think this gets cleaned up by the python tags.

This code runs fine for me:
choices = list("ABCD")
menu = ""
opts1 = []
for idx, choice in enumerate(choices):
    menu += str(idx).ljust(6) + choice + "\n"
    opts1.append(str(idx))
But this code that looks identical generates the error you are seeing.
choices = list("ABCD")
menu = ""
opts1 = []
for idx, choice in enumerate(choices):
    menu += str(idx).ljust(6) + choice + "\n"
	opts1.append(str(idx))  # Starts with a tab instead of 4 spaces.
Error:
opts1.append(str(idx)) TabError: inconsistent use of tabs and spaces in indentation
Next time you post be sure to include the entire error message.
johnywhy likes this post
Reply


Messages In This Thread
Append inside for? - by johnywhy - Jan-13-2024, 06:46 PM
RE: Append inside for? - by deanhystad - Jan-13-2024, 07:06 PM
RE: Append inside for? - by johnywhy - Jan-13-2024, 07:14 PM
RE: Append inside for? - by noisefloor - Jan-13-2024, 07:28 PM
RE: Append inside for? - by johnywhy - Jan-13-2024, 09:32 PM
RE: Append inside for? - by deanhystad - Jan-14-2024, 01:19 AM
RE: Append inside for? - by johnywhy - Jan-14-2024, 04:50 AM
RE: Append inside for? - by deanhystad - Jan-14-2024, 01:11 PM
RE: Append inside for? - by johnywhy - Jan-15-2024, 12:13 AM
RE: Append inside for? - by Gribouillis - Jan-15-2024, 08:33 AM
RE: Append inside for? - by johnywhy - Jan-15-2024, 11:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,703 Apr-22-2020, 01:01 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020