> The question is, what behaviour is preferable for this code:
> 
>     g = 1
>     def f():
>         g += 1
> 
>     f()
> 
> Should this raise an UnboundLocalError or should it increment g?

I think it should increment (i.e. rebind) g, for the same reason that

        g = [1]
        def f():
                g[0] += 1
        f()

rebinds g[0].



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to