[Zope] Scoping question (Python scripts)

Kirby Urner pdx4d@teleport.com
Mon, 09 Apr 2001 08:56:54 -0700


At 11:39 AM 4/9/2001 +0200, Martijn Pieters wrote:

<<SNIP>>
>A python Script is a function in itself, so it's namespace isn't the
>global module space you are expecting. Normally, you would indeed expect
>function() and add2() to be visible throughout your script, as they have
>been defined at the module level.
<<SNIP>>
>-- 
>Martijn Pieters
>| Software Engineer  mailto:mj@digicool.com
>| Digital Creations  http://www.digicool.com/
>| Creators of Zope   http://www.zope.org/
>---------------------------------------------

Thank you sir, this was a trully helpful clue.  This explains
a lot of my mental difficulties.

Here's another question along the same lines -- directed to 
anyone (like, I understand if you're busy).  

Even in an earlier Python like 1.5.2 I believe it's legal to 
write a function like this:

==========

def f():

   class test:

      def d(self,n):
         return n+100
      
      def c(self,n):
         n = n + self.d(n)
         return n+10
      
   om = test()
   j = om.c(3)
   return j

==========

There's a class defined internally to the function.  The above works for 
me in regular Python (2.1 beta -- but I'm not depending on nested scopes, 
no importing from __future___, and no warnings for not).

However, if I strip off the top line and make the rest be a "function 
body" ala a Zope script (de-indent the rest of the lines), like this:

==========

class test:

    def d(self,n):
         return n+100
      
    def c(self,n):
         n = n + self.d(n)
         return n+10
      
om = test()
j = om.c(3)
return j

==========

...then when I try to save it I get:

Forbidden operation STORE_NAME at line 4
Forbidden operation STORE_NAME at line 7

So is there something about Python classes that they can't
be defined internally to an ordinary function/script?  

I've been seeing a lot of text about "publishing a product" 
which involves doing some bookkeeping stuff I was hoping
to avoid.

The on-line docs seem to go from "Hello world" type scripts 
(and vaccinating a hippo) to publishing products, without 
a whole lot in between (and so my train of thought keeps 
falling through the cracks).

Kirby