On Tue, Dec 11, 2007 at 08:36:54AM -0600, Chris Mellon wrote regarding Re: Dumb 
newbie back in shell:
> Delivered-To: [EMAIL PROTECTED]
> Date: Tue, 11 Dec 2007 08:36:54 -0600
> From: "Chris Mellon" <[EMAIL PROTECTED]>
> To: "python-list@python.org" <python-list@python.org>
> Subject: Re: Dumb newbie back in shell
> In-Reply-To: <[EMAIL PROTECTED]>
> Precedence: list
> List-Id: General discussion list for the Python programming language
>       <python-list.python.org>
> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
>       <mailto:[EMAIL PROTECTED]>
> List-Archive: <http://mail.python.org/pipermail/python-list>
> List-Post: <mailto:python-list@python.org>
> List-Help: <mailto:[EMAIL PROTECTED]>
> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
>       <mailto:[EMAIL PROTECTED]>
> Errors-To: [EMAIL PROTECTED]
> 
> On Dec 11, 2007 8:23 AM, J. Clifford Dyer <[EMAIL PROTECTED]> wrote:
> > The code you just posted doesn't compile successfully.
> >
> 
> It *compiles* fine, but it'll raise an error when run.
> 
> > However, in your code, you probably have char_ptr defined at the module 
> > level, and you're confused because you didn't declare it as global.  Am I 
> > right?  My crystal ball has a smudge on it, but I think I can still see 
> > okay.
> >
> 
> I assume that's what he think he's seeing also.
> 
> > You can still reference module level variables that aren't declared as 
> > global, but you can't assign to them.  Or rather, when you try to, you 
> > create a new local variable that shadows the global one.
> >
> 
> No, the determination of what names are local and which are global
> happens at compile time. The code as posted will not run correctly. It
> could run if it weren't in a function and were executed in global
> scope.
> 
> What's probably happening is that line_ptr < last_line is not true and
> the body of the function isn't executed at all. The unbound local
> exception is a runtime error that occurs when the local is accessed,
> not when the function is compiled.

Drat!  You're right.  I tried it in the interactive interpeter, and the 
function compiled just fine.  I tried calling the function and got an 
"UnboundLocalError."  I think I need to go sit in the corner and review the 
documentation.

Sorry all.  Disregard my previous post.

Chris, many thanks for your corrections.

Cheers,
Cliff
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to