Newbie: Usage of this(), self, context
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? regards Christian ________________________________________________________________ Keine verlorenen Lotto-Quittungen, keine vergessenen Gewinne mehr! Beim WEB.DE Lottoservice: http://tippen2.web.de/?x=13
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 ;-) HTH, Stefan
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 ;-)
c.koll@web.de writes:
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? "this" is a method of "SimpleItem.SimpleItem". It returns the object. It is used in DTML Methods, to access the "client". It is also used, to access the nearest acquisition ancestor which is a SimpleItem.
"context" is used in a Python Script. It is the object which was used to access the Python Script. "self" is often used as the first parameter of an External Method. In some cases, calling magic automatically passes an object that is equivalent to "context" for Python Scripts. Read the corresponding sections in <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> for details. Dieter
participants (4)
-
c.koll@web.de -
Dieter Maurer -
Stefan H. Holek -
Thomas B. Passin