Re: [Zope-dev] Problem using External Method

2001-01-24 Thread Shane Hathaway

"Espen S. Frederiksen" wrote:
 
 The problem occur when I try to split up the function as
 shown below. I would like to store the data list, update it
 if nessesary and return it when appropriate. Am I making it
 unessesary complex when I use the class? Is there maybe a
 way to declare the data list global within the module? Or
 is there another, possibly different, way to do this?

Take out all the "import __main__" statements and you should be fine.

Python lets you access two namespaces at once: the "local" namespace and
the "global" namespace.  Were it not for the global namespace, you would
need to do something like "import __main__".  But since globals are
there, everything available at the module level is also available at the
function level.

Shane

 class Testclass:
 def setdata(self,val1,val2,val3):
 self.data = [val1,val2,val3]
 def updatedata(self, index):
 self.data[index] = self.data[index]+1
 def display(self):
 return self.data
 
 x = Testclass()
 
 def createdata(var1, var2, var3):
 import __main__
 x.setdata(var1, var2, var3)
 
 def update(index):
 import __main__
 x.updatedata(index)
 
 def returndata():
 import __main__
 return x.display()

___
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 )




Re: [Zope-dev] Problem using External Method

2001-01-24 Thread Shane Hathaway

On Wed, 24 Jan 2001, Espen Sorbye Frederiksen wrote:
 I did what you suggested, but I am still a bit stuck. Maybe I call them
 wrong in my code. I use the call below but get an error.

 dtml-call expr="createdata('test1','test2','test3')"
 dtml-var expr="returndata()"

 Error Type: AttributeError
 Error Value: data

 any suggestions what I do wrong,

I suggest you run Zope in "-D" mode so you can see tracebacks easily.
They can pinpoint the exact source of problems like this.

Shane


___
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] Problem using External Method

2001-01-23 Thread Espen Sorbye Frederiksen

The module below works using the python compiler
class Testclass:
def setdata(self,val1,val2,val3):
self.data = [val1,val2,val3]
def updatedata(self, index):
self.data[index] = self.data[index]+1
def display(self):
print self.data

x = Testclass() 
def createdata():
import __main__
__main__.x.setdata(10, 20, 30)
__main__.x.updateLog(2)
__main__.x.display()

createdata()
[10,20,31]

However if I try to add it as an External Method( id= createdata) it
doesn't
seem to work. I've tried to call it using dtml-var/call createdata
without success. Any suggestions what I do wrong.
I am grateful for all comments,

Espen


___
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 )




Re: [Zope-dev] Problem using External Method

2001-01-23 Thread Chris McDonough

Espen,

The files that external methods actually live in are not Python modules,
like normal Python modules.  Though I haven't tried your example, it's
likely that your reference to __main__ is confusing the external method
machinery.  Additionally, the output of "print" doesn't go to the remote
browser, it instead goes to the console.  You need to return a value to the
caller for it to be displayed on the remote browser.

Try instead (as an example):

class Testclass:
def setdata(self,val1,val2,val3):
self.data = [val1,val2,val3]
def updatedata(self, index):
self.data[index] = self.data[index]+1
def display(self):
print self.data

def createdata():
x = Testclass()
x.setdata(10, 20, 30)
x.updatedata(2)
return x.display()

- Original Message -
From: "Espen Sorbye Frederiksen" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, January 23, 2001 5:52 PM
Subject: [Zope-dev] "Problem" using External Method


 The module below works using the python compiler
 class Testclass:
 def setdata(self,val1,val2,val3):
 self.data = [val1,val2,val3]
 def updatedata(self, index):
 self.data[index] = self.data[index]+1
 def display(self):
 print self.data

 x = Testclass()
 def createdata():
 import __main__
 __main__.x.setdata(10, 20, 30)
 __main__.x.updateLog(2)
 __main__.x.display()

 createdata()
 [10,20,31]

 However if I try to add it as an External Method( id= createdata) it
 doesn't
 seem to work. I've tried to call it using dtml-var/call createdata
 without success. Any suggestions what I do wrong.
 I am grateful for all comments,

 Espen


 ___
 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 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 )




Re: [Zope-dev] Problem using External Method

2001-01-23 Thread Chris McDonough

Ooops, replace "print self.data" with "return self.data" in the display
method of my Testclass.


- Original Message -
From: "Chris McDonough" [EMAIL PROTECTED]
To: "Espen Sorbye Frederiksen" [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Tuesday, January 23, 2001 6:46 PM
Subject: Re: [Zope-dev] "Problem" using External Method


 Espen,

 The files that external methods actually live in are not Python modules,
 like normal Python modules.  Though I haven't tried your example, it's
 likely that your reference to __main__ is confusing the external method
 machinery.  Additionally, the output of "print" doesn't go to the remote
 browser, it instead goes to the console.  You need to return a value to
the
 caller for it to be displayed on the remote browser.

 Try instead (as an example):

 class Testclass:
 def setdata(self,val1,val2,val3):
 self.data = [val1,val2,val3]
 def updatedata(self, index):
 self.data[index] = self.data[index]+1
 def display(self):
 print self.data

 def createdata():
 x = Testclass()
 x.setdata(10, 20, 30)
 x.updatedata(2)
 return x.display()

 - Original Message -
 From: "Espen Sorbye Frederiksen" [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Tuesday, January 23, 2001 5:52 PM
 Subject: [Zope-dev] "Problem" using External Method


  The module below works using the python compiler
  class Testclass:
  def setdata(self,val1,val2,val3):
  self.data = [val1,val2,val3]
  def updatedata(self, index):
  self.data[index] = self.data[index]+1
  def display(self):
  print self.data
 
  x = Testclass()
  def createdata():
  import __main__
  __main__.x.setdata(10, 20, 30)
  __main__.x.updateLog(2)
  __main__.x.display()
 
  createdata()
  [10,20,31]
 
  However if I try to add it as an External Method( id= createdata) it
  doesn't
  seem to work. I've tried to call it using dtml-var/call createdata
  without success. Any suggestions what I do wrong.
  I am grateful for all comments,
 
  Espen
 
 
  ___
  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 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 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 )