"AndyL" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > if type(key).__name__ == "int" or type(key).__name__ == "long": > abc() > elif type(key).__name__ == "str": > efg() > elif type(key).__name__ == "tuple" or type(key).__name__ == "list": > ijk() > > > In other words I need to determinie intiger type or string or []/() in > elegant way, possibly without or ... > > Thx, A.
Your literal Pythonic approach is to use the isinstance() builtin: if isinstance(key,(int,long)): abc() elif isinstance(key,str): efg(): elif isinstance(key,(tuple,list)): ijk() But since you are dispatching to a method based on type (or some other type of enumerated condition), even more Pythonic is to use a dict to create a dispatch table: dispatch = { int : abc, long : abc, str : efg, tuple : ijk, list : ijk, } try: fn = dispatch[ type(key) ] except KeyError: print "No handler for key of type", type(key) else: fn() -- Paul -- http://mail.python.org/mailman/listinfo/python-list