[Zope] Question about Python Methods Product

David C. Morrill dmorrill@austin.rr.com
Sat, 25 Sep 1999 18:07:46 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_00B1_01BF0780.DE99E860
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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:=20
   Error Type: TypeError
   Error Value: len() of unsized object

If I change the parameter list to: 'self,a=3D1' 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=3D'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





------=_NextPart_000_00B1_01BF0780.DE99E860
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I just finished downloading the Python =
Methods=20
Product tarball, and after playing around with it for a while, I am =
totally=20
confused. I'm hoping someone can help straighten me out...</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Are the&nbsp;Python Methods you create =
supposed to=20
be methods or functions?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>For example, if I enter:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Parameter list: self</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Body: return self.id</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I get the error message: </FONT></DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>&nbsp;&nbsp; Error Type:=20
TypeError<BR>&nbsp;&nbsp; Error Value: len() of unsized=20
object</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><STRONG></STRONG></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>If I change the parameter list =
to:=20
'self,a=3D1' the method is defined successully (note that 'self,a' gets =
the same=20
error as above).</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><STRONG></STRONG></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>If I then click on 'TryIt', I =
get the name=20
of the folder containing the Python Method (as I was=20
hoping).</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><STRONG></STRONG></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>Now, if I use &lt;dtml-var =
myMethod&gt; in=20
a DTML method, I get the same result as 'TryIt'. But if I use =
&lt;dtml-var=20
"myMethod('xxx')"&gt;, I get the error:</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>
<P><STRONG>&nbsp;&nbsp; Error Type:=20
AttributeError</STRONG><BR><STRONG>&nbsp;&nbsp; Error Value: 'string' =
object has=20
no attribute 'id'</STRONG></P>
<P>which makes sense if it is a function, since 'xxx' gets bound to =
'self'=20
instead of 'a'. But then why does it work like a method when no args are =
passed?=20
I just noticed that &lt;dtml-var "myMethod(a=3D'xxx')"&gt; seems to work =

correctly.</P>
<P>I'm not really a Zope or Python expert, so I don't know if I'm =
dealing with a=20
bug or a problem in my understanding. Any help explaining these =
phenomena will=20
be appreciated.</P>
<P>Also, it would be nice if the 'TryIt' tab allowed you to enter =
arguments,=20
like a Z SQL Method does. It would really help trying out methods which =
take=20
arguments, without having to write a DTML method/document first. Just a =
future=20
wish list item :-)</P>
<P>Dave Morrill<BR></P><BR></DIV></STRONG></FONT></BODY></HTML>

------=_NextPart_000_00B1_01BF0780.DE99E860--