[BangPypers] Python "Wat"s

Ramchandra Apte maniandram01 at gmail.com
Tue Sep 10 07:16:12 CEST 2013


I get UnboundLocalError: local variable 'x' referenced before assignment.
That's strange, I'd expect the first print statement to print 10, not
generate an exception.



On 10 September 2013 10:39, Anand Chitipothu <anandology at gmail.com> wrote:

> On Tue, Sep 10, 2013 at 10:37 AM, Ramchandra Apte <maniandram01 at gmail.com
> >wrote:
>
> > On 10 September 2013 10:21, Anand Chitipothu <anandology at gmail.com>
> wrote:
> >
> > > On Tue, Sep 10, 2013 at 10:14 AM, Shabda Raaj <shabda at agiliq.com>
> wrote:
> > >
> > > > This is a popular talk on quircks of ruby/js
> > > >
> > > > https://www.destroyallsoftware.com/talks/wat
> > > >
> > > > What are the quircks/unexpected behavior you find in Python? (Aka
> > Python
> > > > "wats").
> > > >
> > >
> > > x = 10
> > >
> > > class Foo:
> > >     print x
> > >     x = 0
> > >     print x
> > >     del x
> > >     print x
> > >
> > > # wat?
> > > _______________________________________________
> > > BangPypers mailing list
> > > BangPypers at python.org
> > > https://mail.python.org/mailman/listinfo/bangpypers
> > >
> >
> > I fail to see how that is a "wat", it worked as I expected. (x is defined
> > in the the scope of Foo, then deleted, so then the last print x will
> > display 10)
> >
>
> Try replacing class Foo: with def foo(): and see what happens.
>
> Anand
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list