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. -- http://mail.python.org/mailman/listinfo/python-list