0

Possible Duplicate:
IndentationError: unindent does not match any outer indentation level

This is my code that I have looked through for a couple of hours. It may be a python bug for Lion. I am using python 2.7.

import os, pygame
from pygame.locals import *
import spritesheet
import sound
from map import Level
level = Level()
level.loadFile("level.map")
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = level.render(spritesheet.spritesheet("spritesheet.bmp"))
pygame.display.set_caption('Game')
character=spritesheet.spritesheet("spritesheet.bmp").image_at(pygame.rect.Rect(64, 64, 32, 32), colorkey = (255, 255, 255))
#Create The Backgound
background.blit(character, (304, 224))
screen.blit(background, (0, 0))
clock = pygame.time.Clock()
level.setTile(1, 1, "3")
pygame.display.flip()
xoffset=0
yoffset=0

while True:
    background = level.render(spritesheet.spritesheet("spritesheet.bmp"))
    background.blit(character, (304, 224))
    screen.blit(background, (0+xoffset, 0+yoffset))
    pygame.display.flip()
    for event in pygame.event.get():
        if event.type==QUIT:
            exit()
        elif event.type == KEYDOWN:
            if event.key == K_w:
                yoffset-=5
            if event.key == s:
                yoffset+=5

It returns this:

File "main.py", line 30
   elif event.type == KEYDOWN:
                          ^
IndentationError: unindent does not match any outer indentation level

I can't find anything wrong with it.

Community
  • 1
  • 1

2 Answers2

5

Make sure you are not mixing tabs and spaces for indentation. It is possible that your editor may think your tab stop is one value (4?), and the python interpreter some other value; if some of your lines are then indented with spaces, and other lines with tabs, your editor will show things as lining up when the python interpreter disagrees.

bdonlan
  • 224,562
  • 31
  • 268
  • 324
1

Your code looks correct. Verify that spaces and tabs haven't been intermixed by running $ python -t yourcode.py. This turns on the tab nanny.

Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485