Error when creating class

F

flaviostz

Hi,

I wrote this small program:

class Simples:


def minha_func (valor1, valor2):
return valor1 - valor2


mf = Simples()

x = mf.minha_func(2, 3)

print x


But when I try execute it, python interpreter gives me this error:
File "/tmp/py91849hI", line 11, in <module>
x = mf.minha_func(2, 3)
TypeError: minha_func() takes exactly 2 arguments (3 given)


Please, help me with this issue.

Thanks,

Flávio
 
D

Diez B. Roggisch

flaviostz said:
Hi,

I wrote this small program:

class Simples:


def minha_func (valor1, valor2):
return valor1 - valor2


mf = Simples()

x = mf.minha_func(2, 3)

print x


But when I try execute it, python interpreter gives me this error:

File "/tmp/py91849hI", line 11, in <module>
x = mf.minha_func(2, 3)
TypeError: minha_func() takes exactly 2 arguments (3 given)


Please, help me with this issue.

You need to declare minha_func with an explicit self-parameter as first
argument. That's the way python passes the instance to methods.

Consult the tutorial:

http://www.python.org/doc/2.5.2/tut/node11.html

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top