None

Fredrik Lundh fredrik at pythonware.com
Tue Oct 23 16:53:03 EDT 2001


(where's the start of this thread?)

someone wrote:
> In the calling program I say:
>
> object.output( fout ) # print to file
> object.output( None) # print to standard output
>
> But Python complains that None is a variable that has not
> been previously set.  Can someone explain?  I thought None
> was the empty object reference. Where have I gone astray?

if you include the exact error message (at least the last line of
the traceback), you'll save the world a lot of guessing...

assuming you get a UnboundLocalError, you might have done
something like this:

def spam():
    ...
    output(None)
    ...
    /50 lines of code snipped/
    ...
    # only use the first item
    egg, None, None = 1, 2, 3

this gives you an "UnboundLocalError: local variable 'None'
referenced before assignment" on the *output* line.

to fix this, change the last line to, say,

    egg, dummy, dummy = 1, 2, 3

</F>





More information about the Python-list mailing list