Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:54:40+00:00 2026-05-29T20:54:40+00:00

I am getting a strange incorrect indentation error that I cannot track down. As

  • 0

I am getting a strange incorrect indentation error that I cannot track down. As far as I know, I did not modify this file since last time it was correctly working.

Edit: Ok it turns out I did modify it unknowingly (obviously something had to have changed since last time). I hit a hotkey in my editor which had turned some tabs into spaces. Thanks!

The error is on line 100: ctrl f for “###”

#!/usr/bin/env python
import sys
from collections import deque #high performance queue "deck"

class Node(object):
        def __init__(self,x,y,history):
                self.locationx = x
                self.locationy = y
                self.data = None
                self.history = history #previous node to go backwards

def printNodePathTrace(inNode,width,height,mapTerrain,frontier):
    #travel backward through node history until history == None is reached
    #print off map of path
    mapPath = mapTerrain
    for i in range(width): #fill map with blanks
        for j in range(height):
            mapPath[i][j] = '-'

    #print frontier list
    print "length of frontier"
    print len(frontier)
    for item in frontier:

        #print item.locationy
        #print item.locationx
        mapPath[item.locationy][item.locationx] = '*'

    #print path found
    done = 0
    count = 0
    currentNode = inNode
    while(done == 0 and count < 50):
        mapPath[currentNode.locationy][currentNode.locationx] = '#'
        if currentNode.history == None:
            done = 1
        currentNode = currentNode.history
        count += 1
    printMap(mapPath)

def printMap(mapTerrain): #horizontal right positive x, verticle down positive y
        for i in mapTerrain:
            for j in i:
                sys.stdout.write(j)
            sys.stdout.write('\n')

def printMapStartAndGoal(mapTerrain,startX,startY,goalX,goalY):
    #Y is row, X is column. Y is vertical, X is horizontal
    temp1 = mapTerrain[startY][startX]
    temp2 = mapTerrain[goalY][goalX]
    mapTerrain[startY][startX] = 'S'
    mapTerrain[goalY][goalX] = 'G'
    printMap(mapTerrain)
    mapTerrain[startY][startX] = temp1
    mapTerrain[goalY][goalX] = temp2

def main():
    #Input map
    #Your program should be able to read a map file in the following format.
    #Width Height
    #StartX StartY
    #GoalX GoalY
    #map
    searchMode = "BFS" #options are BFS, LC, ID, A*1, A*2

    logfile = open("smallmap2.txt", "r")
    [width,height] = map(int,logfile.readline().split())
    [startX,startY] = map(int,logfile.readline().split())
    [goalX,goalY] = map(int,logfile.readline().split())

    mapTerrainInput = logfile.read()
    mapTerrain = map(list,mapTerrainInput.splitlines())
    #map the list function to mapTerrainInput split into lines without '\n'

    printMapStartAndGoal(mapTerrain,startX,startY,goalX,goalY)

    print mapTerrain
    printMap(mapTerrain)

    closedList = [] #contains list of nodes visited already
    frontier = deque([])
    startNode = Node(startX,startY,None)

    #check if node is a goal node
    #add node to closed list
    #add expansions to frontier list (not ones on closed list)
    #Repeat with next node in Frontier

    goalFound = 0 ### there's an error with this line's indentation???
    iterationCount = 0
    currentNode = startNode
    while goalFound == 0 and iterationCount < 500: #stop when goal is found
            if (currentNode.locationx == goalX and currentNode.locationy == goalY):
                    goalFound = 1
                    break

            closedList.append(currentNode)
            #expand node - currently not checking the closed list
            if (currentNode.locationy > 0): #can expand up
                frontier.append(Node(currentNode.locationx,currentNode.locationy - 1,currentNode))
            if (currentNode.locationy < height - 1): #can expand down
                frontier.append(Node(currentNode.locationx,currentNode.locationy + 1,currentNode))
            if (currentNode.locationx > 0): #can expand left
                frontier.append(Node(currentNode.locationx - 1,currentNode.locationy,currentNode))
            if (currentNode.locationx < width -1): #can expand right
                frontier.append(Node(currentNode.locationx + 1,currentNode.locationy,currentNode))
            #done expanding

            currentNode = frontier.popleft()
            iterationCount += 1


    print currentNode.history
    print currentNode.locationx
    print currentNode.locationy

    printNodePathTrace(currentNode,width,height,mapTerrain,closedList)


if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:54:41+00:00Added an answer on May 29, 2026 at 8:54 pm

    As other answers have mentioned, your issue is that you are mixing tabs and spaces, here is some proof:

    enter image description here

    I took this screenshot while “editing” your answer, and then searched for four spaces. All occurrences of four spaces are highlighted in yellow.

    Note that the spacing immediately before goalFound = 0 is highlighted, but previous lines have non-highlighted spacing (indicating that tabs were used).

    You should never mix tabs and spaces in your indentation because it can be hard to catch errors like this. Python treats tabs as eight spaces, but depending on your editor tabs may look equivalent to 4 spaces (or some other number). So even though your code looks like it is correctly indented, what Python actually sees looks like this:

    def main():
            #... all previous lines used tabs
            #Repeat with next node in Frontier
    
        goalFound = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a strange error in Firebug, that I am not getting in
I'm getting a strange syntax error when I run this in VB: SQLString =
Getting this strange error. In C#, I write to a file (txt) whose location
I'm getting a strange error that only occurs on the live server. My Django
I'm getting strange error 'int' object has no attribute 'startswith' I haven't used the
I'm getting a strange error when I use F# to read a public readonly
I am getting a strange error using jQuery 1.3.2 and Firefox. I have created
i am getting a strange bundler error when running bundle pack with bundler 0.9.12
I am getting strange error while inserting data into mysql table column. Details: Create
I've looked at this article and am getting strange behavior in a HAML partial.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.