[Python-ideas] local is safer than global

Cesare Di Mauro cesare.di.mauro at gmail.com
Sun Jun 13 15:39:55 CEST 2010


2010/6/13 Antoine Pitrou <solipsis at pitrou.net>

> On Fri, 11 Jun 2010 21:18:48 -0400
> Demur Rumed <junkmute at hotmail.com> wrote:
> >
> > For example,
> >
> > def f(x):
> >     a.append(x)
> >     if len(a)>5:a=[5]
> >
> > If a is bound as a local, this throws an UnboundLocalError. Why then is
> it not set to try the global namespace, that place we cannot be so certain
> of the exception in?
> >
> > It comes down to the view of UnboundLocalError as a feature or a bug
>
> Certainly a feature. In case of ambiguity, a variable should be
> considered local rather than global. It makes the language much safer.
>
> It's also why I'm -1 on your proposal.
>
> Regards
>
> Antoine.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas


Locals are also MUCH faster...

Cesare
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100613/bffdf3db/attachment.html>


More information about the Python-ideas mailing list