Confused with methods
From: jfj (jfj_at_freemail.gr)
Date: 02/07/05
- Next message: Lee Harr: "Re: OT: why are LAMP sites slow?"
- Previous message: moma: "Re: Python versus Perl ?"
- Next in thread: Matthias Kempka: "Re: Confused with methods"
- Maybe reply: Matthias Kempka: "Re: Confused with methods"
- Reply: Dan Perl: "Re: Confused with methods"
- Reply: Alex Martelli: "Re: Confused with methods"
- Maybe reply: Alex Martelli: "Re: Confused with methods"
- Maybe reply: Fredrik Lundh: "Re: Confused with methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 06 Feb 2005 17:39:40 -0800 To: python-list@python.org
I don't understand.
We can take a function and attach it to an object, and then call it
as an instance method as long as it has at least one argument:
#############
class A:
pass
def foo(x):
print x
A.foo = foo
a=A()
a.foo()
#############
However this is not possible for another instance method:
############
class A:
pass
class B:
def foo(x,y)
print x,y
b=B()
A.foo = b.foo
a=A()
# error!!!
a.foo()
##############
Python complains that 'foo() takes exactly 2 arguments (1 given)'.
But by calling "b.foo(1)" we prove that it is indeed a function which takes
exactly one argument.
Isn't that inconsistent?
Thanks,
Gerald.
- Next message: Lee Harr: "Re: OT: why are LAMP sites slow?"
- Previous message: moma: "Re: Python versus Perl ?"
- Next in thread: Matthias Kempka: "Re: Confused with methods"
- Maybe reply: Matthias Kempka: "Re: Confused with methods"
- Reply: Dan Perl: "Re: Confused with methods"
- Reply: Alex Martelli: "Re: Confused with methods"
- Maybe reply: Alex Martelli: "Re: Confused with methods"
- Maybe reply: Fredrik Lundh: "Re: Confused with methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|