From: D-Man <ds...@ri...> - 2001-07-16 16:19:32
|
On Mon, Jul 16, 2001 at 05:00:19PM +0200, Kevin McNamee wrote: | Is there anyway to find out the type of an object? E.g. | | >>> a = 1 | >>> a.isa(int) | 1 >>> a=1 >>> type( a ) <jclass org.python.core.PyInteger at 6284031> >>> import types >>> print type(a) == types.IntType 1 >>> print a.__class__ org.python.core.PyInteger >>> print isInstance( a , types.IntType ) Traceback (innermost last): File "<console>", line 1, in ? NameError: isInstance >>> [ aside : Hey, where'd "isInstance" go? ] Check out the 'types' module too. That is good for built-in types which, in CPython but not Jython, are different from class instances. The isInstance function is better because it works with classes too. The only problem with it is I don't know what object to pass in as the "class" of the built-in types. (Also it doesn't seem to be a built-in function in Jython) HTH, -D |