I put the following code and it works fine:

=== controller ===

class MyClass(object):
    z = 2
    def __init__(self, a, b):
        self.x = a
        self.y = b
    def add(self):
        return self.x + self.y + self.z

def index():
    myinstance = MyClass(3, 4)
    add = myinstance.add()
    return dict(add = add)

=== view ===
{{=add}}

On 21 mayo, 07:59, Anthony <abasta...@gmail.com> wrote:
> I think you want:
>
> self.x,self.y = a,b
>
> When you get a Python error, try the code in a Python shell first so you can
> easily see whether the problem is web2py-specific or just a Python issue.
>
> Anthony
>
>
>
>
>
>
>
> On Saturday, May 21, 2011 6:00:02 AM UTC-4, 黄祥 wrote:
> > hi,
>
> > is there any class example on book or appliances, so that i can learn
> > from it?
> > i've already tried the simple things what written on book, but got an
> > error. do you have any hints or solutions?
> > thank you so much before
>
> > e.g.
> > === controller ===
>
> > class MyClass(object):
> >     z = 2
> >     def __init__(self, a, b):
> >         self.x = a, self.y = b
> >     def add(self):
> >         return self.x + self.y + self.z
>
> > def index():
> >     myinstance = MyClass(3, 4)
> >     add = myinstance.add()
> >     return dict(add = add)
>
> > === view ===
> > {{add}}

Reply via email to