Re: [Zope-dev] Adding functions to _
From: Itamar Shtull-Trauring <[EMAIL PROTECTED]> > However, when I call the function, I get an error about DocumentTemplate, > from which I discovered that when I call _.logvis('a_string'), instead of > the string being passed as the first parameter, _ is passed as the first > parameter to my function, forcing me to truncate it when calling log2vis: > Any idea what could cause this strange behaviour? it doesn't happen for > other functions inserted into _ in DT_Util.py. When you stuff a function into "d", you're adding it to the class dictionary of DocumentTemplate, so it effectively becomes a method of that class. The first argument gets treated as "self", just like in any other class method. All of the functions in DT_Util are either builtins (which never get turned into bound methods) or functions with a leading "self" parameter. Cheers, Evan @ digicool & 4-am ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
[Zope-dev] Adding functions to _
I'm using CVS Zope, and I want to add a function of mine to _, so I have the following code in a Product's __init__.py: from log2vis import log2vis from DocumentTemplate.DT_Util import d d["log2vis"] = log2vis However, when I call the function, I get an error about DocumentTemplate, from which I discovered that when I call _.logvis('a_string'), instead of the string being passed as the first parameter, _ is passed as the first parameter to my function, forcing me to truncate it when calling log2vis: from log2vis import log2vis from DocumentTemplate.DT_Util import d def log2vis_wrapper(*args, **kwargs): return apply(log2vis, args[1:], kwargs) d["log2vis"] = log2vis_wrapper Any idea what could cause this strange behaviour? it doesn't happen for other functions inserted into _ in DT_Util.py. -- Itamar S.T. [EMAIL PROTECTED] Fingerprint = D365 7BE8 B81E 2B18 6534 025E D0E7 92DB E441 411C ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )