Instance methods vs. functions and the self parameter
Roman Suzi
rnd at onego.ru
Sun Feb 2 09:44:56 EST 2003
What is we try to look at the types:
>>> class Class:
... def method(self):
... print "I have a self!"
...
>>> def function():
... print "I don't..."
...
>>> instance = Class()
>>> instance.method
<bound method Class.method of <__main__.Class instance at 0x8161344>>
>>>
>>> instance.method1 = function
>>> instance.method1
<function function at 0x8160eec>
>>>
>>> Class.method2 = function
>>> instance.method2
<bound method Class.function of <__main__.Class instance at 0x8161344>>
It can be seen that attribute instance.method1 is a function, not method
at all...
(I made method names differ because otherwise class method is
in shadow)
Sincerely yours, Roman Suzi
--
rnd at onego.ru =\= My AI powered by Linux RedHat 7.3
More information about the Python-list
mailing list