[Tutor] "expected an indented block" (see attached)
mehgcap at gmail.com
Thu Jul 22 16:24:14 CEST 2010
On 7/22/10, Hugo Arts <hugo.yoshi at gmail.com> wrote:
> 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.
I think a specialized editor is all it would take. Edsharp
(http://www.empowermentzone.com/edsetup.exe) has a way of converting
braced code into Pythonic indents and colons, but you then have to
manage two sets of files, the braced code and the indented code.
Perhaps such an editor is a future project for me...
> 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).
Tabs are worse because, for some very annoying reason, my reader reads
both hard returns and tabs as the word "blank". That means that I have
no way of knowing when I am reading a tab and when I have gone to a
previous line. Spaces are the only viable option.
Thanks for the script; if I have to attach code in the future, I will
try to remember to run the file(s) through it for easier reading. I
can also make your script remove the #end... comments, since I know a
lot of people do not like them either.
> 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.
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap
More information about the Tutor