problems with the types module
Ronald Oussoren
oussoren at cistron.nl
Thu Dec 12 02:58:31 EST 2002
More information about the Python-list mailing list
Thu Dec 12 02:58:31 EST 2002
- Previous message (by thread): problems with the types module
- Next message (by thread): problems with the types module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wednesday, Dec 11, 2002, at 22:20 Europe/Amsterdam, David Necas (Yeti) wrote: > On Wed, Dec 11, 2002 at 01:05:53PM -0800, Erik Max Francis wrote: >> Michele Simionato wrote: >> >>> i.e. the same object is seen as a function inside the class scope and >>> as an >>> instance method outside the class scope. To me, this fact was quite >>> surprising, >>> I don't like to have a changing type depending on the context. Maybe >>> a >>> unique >>> 'function' type for both functions and methods would have been a >>> simpler >>> solution. >> >> But they're not the same. Remember that first "self" argument; >> functions and methods are handled differently, so a distinction needs >> to >> be made. > > IIUC type(object) doesn't return type of the object, as we > all thought and as is written everywhere. The underlying > object is unique and can have only one type (and it has not > a name, since it's just some thing in memory). type(value) does return the type of the object, the examples of the OP just print the types of different objects: class Foo: def bar(self): pass print id(bar), type(bar) print id(Foo.bar), type(Foo.bar) On my system this prints: 1118848 <type 'function'> 1155808 <type 'instance method'> When class Foo is constructed the function object 'bar' is converted to an instancemethod object. Ronald
- Previous message (by thread): problems with the types module
- Next message (by thread): problems with the types module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list