correct way to detect container type

Robin Becker robin at reportlab.com
Thu Oct 7 11:30:22 CEST 2004


I seem often to allow list/tuple arguments to be a singleton. This leads to code 
of the form

if type(arg) not in (type(()),type([])): arg = [arg]


or alternatively

from type import ListType, TupleType
_seqTypes = ListType, TupleType
......
if type(arg) not in _seqTypes: ....

is there a 'best' way to do this?
-- 
Robin Becker



More information about the Python-list mailing list