Dumb newbie back in shell
J. Clifford Dyer
jcd at sdf.lonestar.org
Tue Dec 11 09:51:22 EST 2007
On Tue, Dec 11, 2007 at 08:36:54AM -0600, Chris Mellon wrote regarding Re: Dumb newbie back in shell:
> Delivered-To: python-list at bag.python.org
> Date: Tue, 11 Dec 2007 08:36:54 -0600
> From: "Chris Mellon" <arkanes at gmail.com>
> To: "python-list at python.org" <python-list at python.org>
> Subject: Re: Dumb newbie back in shell
> In-Reply-To: <20071211142341.GA20275 at sdf.lonestar.org>
> 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:python-list-request at python.org?subject=unsubscribe>
> List-Archive: <http://mail.python.org/pipermail/python-list>
> List-Post: <mailto:python-list at python.org>
> List-Help: <mailto:python-list-request at python.org?subject=help>
> List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
> <mailto:python-list-request at python.org?subject=subscribe>
> Errors-To: python-list-bounces+jcd=sdf.lonestar.org at python.org
>
> On Dec 11, 2007 8:23 AM, J. Clifford Dyer <jcd at sdf.lonestar.org> 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
More information about the Python-list
mailing list