[Zope] calling product ZClass add method

Andreas Kostyrka andreas@mtg.co.at
Mon, 23 Aug 1999 20:52:35 +0200 (CEST)


On Mon, 23 Aug 1999, Chris Walter wrote:

> BTW as far as I am concerned you are a genius for figuring out the
> line:
> 
> <dtml-with "manage_addProduct['YourProduct']">
> 
> by looking at the HTML source.  I don't really know python yet.  What
> is the meaning of the "[]" as opposed to the "()"?  Array instead of
> function?
Well, () is function call.
[] is index lookup (be it numeric in an array, or any type for a
dictionary).

Put differently, in the python object model, () translates to the method
__call__ and [] translates to the methods
__getitem__/__setitem__/__delitem__

Example:
class A:
	def __getitem__(self,k):
		print "GET",k
	def __setitem__(self,k,v):
		print "SET",k,"=",v
	def __delitem__(self,k):
		print "DEL",k
	def __call__(self,*args):
		print "CALL",args

# create an instance a of our demonstration class.
a=A()

# now do some accesses:
x=a[5]
a[6]="ABC"
del a[1,2]
x=a(1,2,3,4)

> In the HOWTO it might be nice to point out that _ is a special
> variable that contains the namespace and people should look in the
> DTML users's guide for more info.
<rant:mode>
Well, the DTML user's guide does point it out. 
:(
People seem to assume that they can start to develop ZOPE applications
just as easy writing some HTML pages with FP :(

Remember: ZOPE is easy. But this is relative to it's power. ZOPE is
extremly powerful. And it's the most powerful development philosophy I've
seen. Because of this ZOPE is just a bit complex. Don't expect to start
using ZOPE and become proficient developers in 1 week.
</rant:mode>

Andreas
--
Andreas Kostyrka                     | andreas@mtg.co.at
phone: +43/1/7070750                 | phone: +43/676/4091256   
MTG Handelsges.m.b.H.                | fax:   +43/1/7065299
Raiffeisenstr. 16/9                  | 2320 Zwoelfaxing AUSTRIA