views:

127

answers:

2

Right now I'm working on a Tetris Game (sorta, I found a Tetris example for Python on a website, I've been copying it but adding some of my own stuff), and just finished writing all the code but have had a couple syntax errors. I've been able to fix all of them but this last syntax error is confusing to me.

    def pieceDropped(self):
        for i in range(4):
            x = self.curX + self.curPiece.x(i)
            y = self.curY - self.curPiece.y(i)
            self.setShapeAt(x, y, self.curPiece.shape()

        self.removeFullLines()

The specific syntax error is on the last line of the function and I don't understand why, the indentation and whitespace all seems correct. So could someone explain how this is a syntax error?

A: 

There's an extra whitespace on the last line - just ahead self.removeFullLines(). Its indenting is thus not the same as the for line's indenting. EDIT: Seems to be corrected now.

Always use the same indent sequence - choose either tabs, or n whitespaces. But be consistent. Some editors (such as VIM) are able to insert the appropriate number of whitespaces whenever you hit tab.

Alexander Gessler
+5  A: 

You didn't close the parenthesis of self.setShapeAt.

Tim Pietzcker
ah. thanks. Didn't see that
Brad Johansen
Happens to me all the time. It's confusing at first that the exception occurs on the line *after* the actual error, but that's understandable since unclosed parentheses implicitly serve as line continuators.
Tim Pietzcker
@Tim That makes sense now. Thanks for the explanation
Brad Johansen