On Wed, Jul 31, 2002 at 09:33:05PM -0700, Mike Orr wrote:
> On Wed, Jul 31, 2002 at 08:39:24PM -0700, Greg Czajkowski wrote:
> > In the following code shouldn't I be able to use $i
> > without declaring it global?
> >
> > from Cheetah.Template import Template
> > print Template(source="""
> > #for $i in range(10)
> > #block testblock
> > testing $i
> > #end block
> > #end for
> > """)
>
> That would work for a Python program in that structure, provided it were
> run on a recent version of Python that does nested scoping. But the
> Cheetah compiler pulls the #block out and puts it in a method at the
> same level as the main method (not nested inside the main method), so
> nested scoping does not apply.
In case it isn't clear, there are several kinds of scoping.
"nested lexical scoping" means that if a function is defined inside
another block of code, it can see the variables in that block. That's
what Python's nested scoping is, and what Perl's "my" variables are.
"nested dynamic scoping" means that when a function is called, it
can see the variables in its caller, no matter where the calling
code is physically defined. Python does not have this. Perl
variables defined without "my" do this, but their use is depreciated.
--
-Mike (Iron) Orr, iron@... (if mail problems: mso@...)
http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol
|