Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6561
| References | <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> <mailman.2217.1306662671.9059.python-list@python.org> <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> <BANLkTinK=dHCbocURD2+s5uvdonBkS+uFQ@mail.gmail.com> <BANLkTimWP+jP0s5DsBaFbv6LV5OTYA8hQw@mail.gmail.com> |
|---|---|
| Date | 2011-05-30 04:38 +1000 |
| Subject | Re: scope of function parameters |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2233.1306694309.9059.python-list@python.org> (permalink) |
On Mon, May 30, 2011 at 4:01 AM, Chris Rebert <clp2@rebertia.com> wrote: > def foo(): > print bar > bar = 42 > > foo() > > ===> > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<stdin>", line 2, in foo > UnboundLocalError: local variable 'bar' referenced before assignment Wow I thought it basically functioned top-down. You get a different error on the print line if there's a "bar = 42" *after* it. This could make debugging quite confusing. Guess it's just one of the consequences of eschewing variable declarations. Sure it's easier, but there's complications down the road. Chris Angelico
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: scope of function parameters Wolfgang Rohdewald <wolfgang@rohdewald.de> - 2011-05-29 11:47 +0200
Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 12:47 +0000
Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 03:53 +1000
Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:28 +0000
Re: scope of function parameters Chris Rebert <clp2@rebertia.com> - 2011-05-29 11:01 -0700
Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 04:38 +1000
Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:53 +0000
Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 05:20 +1000
Re: scope of function parameters Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-29 13:12 -0600
csiph-web