Correct way to detect sequence parameter?
Posted
by noamtm
on Stack Overflow
See other posts from Stack Overflow
or by noamtm
Published on 2008-11-20T13:52:44Z
Indexed on
2010/03/30
20:33 UTC
Read the original article
Hit count: 340
I want to write a function that accepts a parameter which can be either a sequence or a single value. The type of value is str, int, etc., but I don't want it to be restricted to a hardcoded list. In other words, I want to know if the parameter X is a sequence or something I have to convert to a sequence to avoid special-casing later. I could do
type(X) in (list, tuple)
but there may be other sequence types I'm not aware of, and no common base class.
-N.
Edit: See my "answer" below for why most of these answers don't help me. Maybe you have something better to suggest.
© Stack Overflow or respective owner