what is the the best way to express following:

AndyL ask at me
Mon Mar 27 20:55:22 EST 2006


Paul McGuire wrote:
> "AndyL" <ask at me> wrote in message news:_uOdnaBMCLmcPLXZRVn-uA at comcast.com...
> 
>>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()
> 

thx a lot . In fact I do not do dispatch, just wanted ilustrate if: 
elif: sequence. Andy



More information about the Python-list mailing list