[Python-ideas] local is safer than global
Antoine Pitrou
solipsis at pitrou.net
Sun Jun 13 15:36:34 CEST 2010
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.
More information about the Python-ideas
mailing list