[Tutor] "expected an indented block" (see attached)
evert.rol at gmail.com
Thu Jul 22 15:35:43 CEST 2010
> Attached is a file. When I run the program it is part of, I get an
> error that says:
> line 62: IndentationError: expected an indented block.
def fromString(self, str):
#creates a Craft object from the string
#end class Craft
Is completely empty (the comment lines are discarded). So Python expects any next piece of code to be inside this method (and thus indented).
If you want an empty function, use 'pass' instead.
(also consider using four spaces for indentation, which I've also found much clearer. Have a read through PEP 8; has a lot of interesting tidbits.
And an editor with a good Python mode is very handy, because that would have almost automatically indented the next piece of code, 'class Battleship(Craft)', which would have indicated something went awry before that line).
> I can see nothing wrong with the indentation, though. This is part of
> my Battleship game, defining all the different ships and aircraft the
> user can have, as well as the special weapons methods for each ship.
> If anyone can spot the problem, it would be great. I know I only
> indent one space, instead of the normal four, but I use a screen
> reader and it is a lot easier and faster to do it this way. If a
> version of Python based on braces instead of indents were released, my
> world would be so much better!
More information about the Tutor