How to detect list versus string

Jonathon McKitrick jcm at
Fri Jun 11 18:12:35 CEST 2004

This sounds simpler that it is, hopefully  ;-)

I have a method that builds a dynamic combo box.  Before I do that, I set a
class variable to the new list of items.

def make_new_cat_box(self, cats):
	self.cat_list = cats

Sounds simple.  But sometimes, my combo box will only have one choice
available.  When I call this method with a list of one string, the string is
split up, and my combo box now has a separate item for each letter in the
string.  What I obviously want to do is detect when the object coming in is
a list or a string.  type() isn't as useful as I had hoped, and len() will
give me the length of the string, so I cannot tell if it is a string or a
list of more that one item.

There has to be a simple solution.

My other computer is your Windows box.

More information about the Python-list mailing list