[ZOPE] Newbie: Usage of this(), self, context
Thomas B. Passin
tpassin@mitretek.org
Fri, 8 Feb 2002 14:23:35 -0500
They are not all exactly the same. "self", in Python - and thus in Python
scripts and external methods - is a placeholder, not a function. You can
call it anything, like this:
class magicClass:
def __init__(this_thing_here):
# Normally people write __init__(self), but
# that is just a convention
Outside of the class definition, "self" is not a keyword and has no
intrinsic meaning in Python, although Zope could perhaps add its own meaning
if it wanted to. Within a class definition, you can call it anything, as
long as you are consistent within the class definition.
this(), on the other hand, is a DTML method call that returns a reference to
the called object. "context", in a python script, refers to the namespace
in effect (that is, the dictionaries that define the attributes and methods
available and in scope).
I don't know the eact meaning of "here" on a page template.
So these aren't really the same things, even if there is some similarity.
[Stefan H. Holek]
At 08.02.2002 15:11 +0100, c.koll@web.de wrote:
>When I read the Zopebook it seemed to be quite understandable, but looking
>at some scripts now, I think I somehow mixed it up. What´s the difference
>between "this()", "self" and "context"? When do I use each one?
When writing | the Zopista uses
----------------------------------
Python Product | self
External Method | self
DTML | this()
Python Script | context
Page Template | here
to refer to basically the same thing.
At this point I feel like a sarcastic comment on orthogonality and such but
words fail me ;-)