strange unbound local error?

righes at arcor.de righes at arcor.de
Sat Sep 29 14:04:39 EDT 2007


hi folks,

suppose this snipplet:

spam = 42

def eggs():
    print spam
    spam = spam + 1

if __name__=="__main__":
    eggs()

This thows an UnboundLocalError at line 4 (print statement). But if I
comment out line 5 (variable assignment), no error occurs.

Can you explain me this, please?

Regards,
Enrico




More information about the Python-list mailing list