[Tutor] email validation

Danny Yoo dyoo at hashcollision.org
Sat Aug 1 23:10:03 CEST 2015

All your function definitions should be defined with 'def' at the
leftmost margin.

However, the line in your program that starts with "def
open_existing_file()..." is not flush with the margin.  Python has,
subsequently, thought that the definition of the function is scoped
locally.  Move the beginning of the definition line "def
open_existing_file()" so that it's not indented.

Conceptually, what's happening is that you've accidentally written a
locally-scoped function definition, which beginner programs do not
typically do.  The following program demonstrates:

def bigFunction():
    def nestedFunction():

    ## at this point forward, nestedFunction can be accessed only
    ## here:

## Try calling bigFunction:
## Try calling nestedFunction (and expect it to fail!)

Try calling bigFunction() from the toplevel.  Then try calling
nestedFunction() directly from the toplevel.  You'll find that you
can't: the definition of nestedFunction is scoped so that its
accessible only after the point commented.

More information about the Tutor mailing list