[Zope-dev] "Problem" using External Method

Espen S. Frederiksen ceeesf@cee.hw.ac.uk
Wed, 24 Jan 2001 13:04:47 +0000 (GMT Standard Time)


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?

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

Thank you for your assistance so far. Hope you have time 
to answer my problem,

Espen

On Tue, 23 Jan 2001 18:46:21 -0500 
Chris McDonough <chrism@digicool.com> wrote:

> 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" <ceeesf@cee.hw.ac.uk>
> To: <zope-dev@zope.org>
> 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  -  Zope-Dev@zope.org
> > 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  -  Zope-Dev@zope.org
> 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 )
> 

--
Espen S. Frederiksen
Vocalist Manifold
Kapellmester Gambrinus
Heriot-Watt University
ceeesf@cee.hw.ac.uk