[Tutor] Shadow error
Andrei Kulakov
ak@silmarill.org
Thu, 26 Jul 2001 18:29:43 -0400
On Fri, Jul 27, 2001 at 12:27:00AM +0200, Kalle Svensson wrote:
> Sez Christopher Smith:
> > <Untitled Script 2>:5: SyntaxWarning: local name 'n' in 'dig' shadows
> > use of 'n' as global in nested scope 'lambda'
> > [0.5, 0.28000000000000003, 0.84999999999999998]
> >
> > So it worked, but there was the complaint which I don't know how to make
> > go away.
>
> This warning was introduced in Python 2.1 together with new scoping
> features. Before, then variable n in the function dig wouldn't have been
> visible inside the lambda, and the n in the lambda would have been a
> reference to a global n. With the new nested scoping, which will become
> default in 2.2, n in dig is visible, which is changed behaviour between
> versions. Thus a warning is issued, to notify programmers that their code
> might have changed meaning. The warning will go away with time, perhaps in
> 2.4 or something like that.
>
> It's also possible to tell it to go away by using the warnings module in
> some way. I'm not sure exactly how, I've never needed it myself, but take a
I think it's from __future__ import nested_scopes at the top of the file.
> look at the docs:
> http://www.python.org/doc/current/lib/module-warnings.html
>
> Hope that made sense...
>
> Peace,
> Kalle
> --
> Free Dmitry Sklyarov! - http://www.freedmitry.org/
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: http://silmarill.org/cymbaline