compare types?
Lulu of the Lotus-Eaters
mertz at gnosis.cx
Wed Jan 1 14:46:05 EST 2003
Gerrit Holl <gerrit at nl.linux.org> wrote previously:
|As I Understand It, you want to know whether something is a list or not.
|Then why use isinstance()? To check whether it's a list, just use type():
| 46 >>> from types import ListType
| 47 >>> type(a) == ListType
|1
>>> from types import *
>>> class NewList(list): pass
...
>>> lst = [1,2,3]
>>> nl = NewList([4,5,6])
>>> type(lst) is ListType
1
>>> type(nl) is ListType
0
>>> isinstance(lst, list)
1
>>> isinstance(nl, list)
1
Of course, it's up to you to decide which answer you are more interested
in. But for most people, the 'isinstance()' answer is more informative.
Yours, Lulu...
--
mertz@ | The specter of free information is haunting the `Net! All the
gnosis | powers of IP- and crypto-tyranny have entered into an unholy
.cx | alliance...ideas have nothing to lose but their chains. Unite
| against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------
More information about the Python-list
mailing list