Namespace weirdness

Paul Winkler slinkp23 at yahoo.com
Sun Jul 9 21:04:24 EDT 2000


Gordon McMillan wrote:
> 
> Paul Winkler wrote:

> >class Food:
> >    def __init__(self, attr1):
> >        self.attr1 = attr1
> >    class BodyPart:
> >        def do_it(self):
> >            # This next line is a stand-in for what I want...
> >            print my_parent_namespace.attr1
> 
> Python doesn't nest class definitions (or function defs) in a way that is
> particularly interesting. Your code creates a class object which is
> accsessible as Food.BodyPart, but BodyPart has no idea it was defined
> inside Food. As far as it's concerned, it is toplevel.

That's what I was afraid of. It does have the useful quality that
it's unrelated to any BodyPart in other namespaces, which is why I
put it in there.
Oh well.
 
> But there is absolutely no cannibalism in Python. None at all.

"Cannibalism" = classes eating classes? not sure what you mean,
sorry.
 
Thanks for the comments.

-- 
.................    paul winkler    ..................
slinkP arts:   music, sound, illustration, design, etc.
        web page:  http://www.ulster.net/~abigoo        
      A member of ARMS:   http://www.reacharms.com
               or http://www.mp3.com/arms



More information about the Python-list mailing list