[Tutor] "expected an indented block" (see attached)

Hugo Arts hugo.yoshi at gmail.com
Thu Jul 22 16:13:35 CEST 2010


On Thu, Jul 22, 2010 at 3:35 PM, Evert Rol <evert.rol at gmail.com> wrote:
>> 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.
>
> This function:
>
>  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.

Did you read the rest of his post? He's using a screen reader for a
reason; he can't *see* the code. visual means of structuring code like
whitespace are meaningless to him at best, and annoying at worst. No
wonder his code is littered with '#end def' comments. Python's
significant indentation is horrible for the blind, at least until we
create a more specialized/better screen reader.

Alex, Perhaps a better solution is to indent with tabs rather than
spaces, though I'm normally opposed to using tabs. Alternatively, run
your files through a script that expands every indent space to four
spaces before posting here. I've attached a bare-bones script that
takes a file and a number as argument, replaces every initial space
with that number of spaces, and writes the result to a new file
(filename is just the old filename with .new appended).

Yes, the script is indented with four spaces, Sorry. I'm sure you
could write a script that does the reverse operation so it becomes a
little more readable for you.

Hugo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: indent.py
Type: text/x-python
Size: 551 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20100722/4c4409f9/attachment-0001.py>


More information about the Tutor mailing list