On Thu, Jul 22, 2010 at 3:35 PM, Evert Rol <evert....@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
#! /usr/bin/env python
import sys

def expand_indent(string, num=4):
    """replace every initial space in string with num spaces"""
    if string[0] == ' ':
        return (' ' * num) + expand_indent(string[1:])
    else:
        return string

if __name__ == '__main__':
    if len(sys.argv) == 3:
        num = int(sys.argv[2])
    else:
        num = 4

    infile = open(sys.argv[1], 'r')
    outfile = open(sys.argv[1] + '.new', 'w')

    for line in infile:
        outfile.write(expand_indent(line, num))
    infile.close()
    outfile.close()
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to