How to tell if function was passed a list or a string?

Ben Finney bignose+hates-spam at benfinney.id.au
Wed May 17 19:31:32 EDT 2006


trebucket at gmail.com writes:

> >>> import types
> >>> type("") is types.ListType
> False
> >>> type("") is types.StringType
> True
> >>> type([]) is types.StringType
> False
> >>> type([]) is types.ListType
> True

This is even worse than an 'isinstance' check; it refuses even
subclasses of the types you accept, breaking polymorphism *and*
inheritance.

-- 
 \         "What you have become is the price you paid to get what you |
  `\                              used to want."  -- Mignon McLaughlin |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list