[gull] python2.5 et type(x)

Daniel Cordey dc at mjt.ch
Thu Jul 31 10:02:52 CEST 2008


On Thursday 31 July 2008 09:23:44 Olivier Bornet wrote:

>     if type(dict[k]) == type({}):

Depuis fort longtemps (< 2001... Python 2.1) il est recommande d'utiliser 
'isinstance()' plutot que 'type()'. On peut ecrire :

	isinstance(3, int)
	isinstance(3, types.IntType)
	isinstance([], list)
	...

"This is the recommended way to perform type-checking with the built-in types, 
as the distinction between types and classes may disappear in a future 
release" (Python - Essential reference - Second edition - New Riders)

dc



More information about the gull mailing list