Unbound method
Andrew M. Kuchling
akuchlin at mems-exchange.org
Tue Jun 22 17:24:26 EDT 1999
faria writes:
>Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
>Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>> from test import *
>>>> x = A
>>>> x.a
>'Greetings from Brasil!!!'
>>>> x.pa
><unbound method A.pa>
x is a class, not an instance. This can be made clearer with
different variable names:
>>> klass = A
>>> instance = A()
>>> klass
<class __main__.A at e21d8>
>>> instance
<__main__.A instance at f22c8>
>>> klass.a
'Greetings from Brasil!!!'
>>> instance.a
'Greetings from Brasil!!!'
>>> klass.pa
<unbound method A.pa>
>>> instance.pa
<method A.pa of A instance at f22c8>
If you're expecting x = A to create an instance of the class A, that
expection is incorrect; you have to do x = A() to create an instance.
--
A.M. Kuchling http://starship.python.net/crew/amk/
In the design of fission reactors man was not an innovator but an unwitting
imitator of nature.
-- George A. Cowan, "A Natural Fission Reactor"
More information about the Python-list
mailing list