[Zope] the context or self in Zope python scripts

Thomas B. Passin tpassin@mitretek.org
Tue, 3 Jul 2001 15:30:41 -0400


[Mate' Sztipanovits]

> i am having trouble with self in external scripts .. does anyone know tyhe
> general idea.
> or more specifically how can i call self.manage_addFile() without Zope
> barfing on self.

If you mean an External Method, that would be an ordinary Python script.
Python does not maintain a variable called "self".  When you see "self" used
in the definition on a class's methods, it is a placeholder to represent a
parameter that will be passed to that method when it is called.

For example, these two definitions are equivalent:

class with_self:
    def __init__(self,property):
        self.property=property

class with_xxx:
    def __init__(xxx,property):
        xxx.property=property

When you create an object of that class, a reference to the object is passed
when you call the method, as in

object_with_xxx=with_xxx("property1")
print object_with_xxx.property

So you see, there wouldn't actually be any reference to a "self" by that
name.  You have to get a reference to the actual object.

Cheers,

Tom P