Question about Python Methods Product
I just finished downloading the Python Methods Product tarball, and after playing around with it for a while, I am totally confused. I'm hoping someone can help straighten me out... Are the Python Methods you create supposed to be methods or functions? For example, if I enter: Parameter list: self Body: return self.id I get the error message: Error Type: TypeError Error Value: len() of unsized object If I change the parameter list to: 'self,a=1' the method is defined successully (note that 'self,a' gets the same error as above). If I then click on 'TryIt', I get the name of the folder containing the Python Method (as I was hoping). Now, if I use <dtml-var myMethod> in a DTML method, I get the same result as 'TryIt'. But if I use <dtml-var "myMethod('xxx')">, I get the error: Error Type: AttributeError Error Value: 'string' object has no attribute 'id' which makes sense if it is a function, since 'xxx' gets bound to 'self' instead of 'a'. But then why does it work like a method when no args are passed? I just noticed that <dtml-var "myMethod(a='xxx')"> seems to work correctly. I'm not really a Zope or Python expert, so I don't know if I'm dealing with a bug or a problem in my understanding. Any help explaining these phenomena will be appreciated. Also, it would be nice if the 'TryIt' tab allowed you to enter arguments, like a Z SQL Method does. It would really help trying out methods which take arguments, without having to write a DTML method/document first. Just a future wish list item :-) Dave Morrill
*PLEASE* try to avoid sending HTML-formatted messages to the mailing list. Netscape Mail crashed three times while I tried to write this reply to your message. "David C. Morrill" wrote: : Are the Python Methods you create supposed to be methods or functions? Both. Actually, they act exactly like External Methods, so the <dtml-var> behavior you describe is normal. : I get the error message: : Error Type: TypeError : Error Value: len() of unsized object You've uncovered a bug :-P It was easy to squish, and as you discovered, it can be avoided by declaring at least one parameter with a default value. : Also, it would be nice if the 'TryIt' tab allowed you to enter arguments, like a Z SQL Method does. I agree; Feel free to contribute a patch <wink>. It's on the To-Do list.
participants (2)
-
David C. Morrill -
Evan Simpson