[Zope] Re: [Zope-dev] pluggable brains - namespace blues

Philipp Auersperg zope@philosoft.at
Fri, 03 Nov 2000 14:45:25 +0100


--=====_97325912511478=_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

the best answers are those answered by yourself:

For all who want to know it:

you have to explicitely give self as an extra parameter:

concerning the example below:

just call: 

rs[0].getName(rs[0]) 

and it works for me. 
Weird, but now I can enjoy my beer....

phil
*********** REPLY SEPARATOR ***********

On 03.11.2000 at 12:30 Philipp Auersperg wrote:
I have a problem with pluggable brains:

1. Given is a ZClass named 'Merchant' that maps to a SQL table 'Merchant'=
 with the columns 'ID' and 'name'.

2. I the ZClass I defined a Python method 'getName' with the body:
   return self.name

3. I have a SQL Method with "select * from merchant" that I bind to the=
 brain class 'Merchant'

4. I define a Python method with the following body:
--------------------------------
rs=3Dself.Merchants()
return rs[0].name
--------------------------------

And now the problems:

That works fine, but when I want to access the Merchant's name through the=
 its member function getName() with the following code:

--------------------------------
rs=3Dself.Merchants()
return rs[0].getName()
--------------------------------

then I get an AttributeError mentioning that 'name' cannot be found.
when I  change the getName() Python method to:
return 42
it works!

It seems that the namespace is somehow shreddered, I have to dig into that=
 but if anybody can help it would spare much time!

So finally my desperate question:
How can I solve/workaround that problem to call methods in pluggable brains=
 that access database-based members from a python method?

thanks in advance
phil


--=====_97325912511478=_
Content-Type: text/html; charset="us-ascii"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff style="FONT-FAMILY: Arial; FONT-SIZE: x-small" 
text=#000000>
<DIV>the best answers are those answered by yourself:</DIV>
<DIV>&nbsp;</DIV>
<DIV>For all who want to know it:</DIV>
<DIV>&nbsp;</DIV>
<DIV>you have to explicitely give self as an extra parameter:</DIV>
<DIV>&nbsp;</DIV>
<DIV>concerning the example below:</DIV>
<DIV>&nbsp;</DIV>
<DIV>just call: </DIV>
<DIV>&nbsp;</DIV>
<DIV>rs[0].getName(rs[0]) </DIV>
<DIV>&nbsp;</DIV>
<DIV>and it works for me. </DIV>
<DIV>Weird, but now I can enjoy my beer....</DIV>
<DIV>&nbsp;</DIV>
<DIV>phil<BR><FONT face=Arial size=2>*********** REPLY SEPARATOR 
***********<BR><BR>On 03.11.2000 at 12:30 Philipp Auersperg wrote:</FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">
  <DIV>I have a problem with pluggable brains:</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>1. Given is a ZClass named 'Merchant' that maps to a SQL table 'Merchant' 
  with the columns 'ID' and 'name'.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>2. I the ZClass I defined a Python method 'getName' with the body:</DIV>
  <DIV>&nbsp;&nbsp; return self.name</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>3. I have a SQL Method with "select * from merchant" that I bind to the 
  brain class 'Merchant'</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>4.&nbsp;I define a Python method with the following body:</DIV>
  <DIV>--------------------------------</DIV>
  <DIV>rs=self.Merchants()<BR>return rs[0].name</DIV>
  <DIV>--------------------------------</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>And now the problems:</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>That works fine, but when I want to access the Merchant's name through 
  the its member function getName() with the following code:</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>--------------------------------</DIV>
  <DIV>rs=self.Merchants()<BR>return rs[0].getName()</DIV>
  <DIV>--------------------------------</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>then I get an AttributeError mentioning that 'name' cannot be 
found.</DIV>
  <DIV>when I&nbsp; change the getName() Python method to:</DIV>
  <DIV>return 42</DIV>
  <DIV>it works!</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>It seems that the namespace is somehow shreddered, I have to dig into 
  that but if anybody can help it would spare much time!</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>So finally my desperate question:</DIV>
  <DIV>How can I solve/workaround that problem to call methods in pluggable 
  brains that access database-based members from a python method?</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>thanks in advance</DIV>
  <DIV>phil</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV><FONT size=2 Arial></BLOCKQUOTE></FONT></BODY></HTML>


--=====_97325912511478=_--