By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

Error when creating class

P: n/a
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:
>>Traceback (most recent call last):
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
Oct 26 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
flaviostz schrieb:
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:
>>>Traceback (most recent call last):
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
Oct 26 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.