check if var is dict

2007-08-13 Thread Astan Chee
Hi, I have a variable, I want to check if it is a dictionary or a string. Is there any better way to do this than I've done. How I did it is by doing a .items() and catching a AttributeError that it raises if its not a dictionary. How do i properly do it? Thanks Astan --

Re: check if var is dict

2007-08-13 Thread Lawrence Oluyede
Astan Chee [EMAIL PROTECTED] wrote: I have a variable, I want to check if it is a dictionary or a string. Is there any better way to do this than I've done. How I did it is by doing a .items() and catching a AttributeError that it raises if its not a dictionary. How do i properly do it? One

Re: check if var is dict

2007-08-13 Thread Bruno Desthuilliers
Astan Chee a écrit : Hi, I have a variable, I want to check if it is a dictionary or a string. Is there any better way to do this than I've done. How I did it is by doing a .items() and catching a AttributeError that it raises if its not a dictionary. How do i properly do it? Checking the

Re: check if var is dict

2007-08-13 Thread Jeff McNeil
You could use 'isinstance' to determine whether or not your object is an instance of a particular class. isinstance({}, dict) True isinstance(, basestring) True Note the use of 'basestring', which will catch unicode as well. -Jeff On 8/13/07, Astan Chee [EMAIL PROTECTED] wrote: Hi, I have

Re: check if var is dict

2007-08-13 Thread Wildemar Wildenburger
Astan Chee wrote: Hi, I have a variable, I want to check if it is a dictionary or a string. Is there any better way to do this than I've done. How I did it is by doing a .items() and catching a AttributeError that it raises if its not a dictionary. How do i properly do it? The way you

Re: check if var is dict

2007-08-13 Thread Bruno Desthuilliers
Jeff McNeil a écrit : (top-post corrected) On 8/13/07, Astan Chee [EMAIL PROTECTED] wrote: Hi, I have a variable, I want to check if it is a dictionary or a string. Is there any better way to do this than I've done. How I did it is by doing a .items() and catching a AttributeError that it

Re: check if var is dict

2007-08-13 Thread simohayha
check String is def isStringLike(anobj): try: anobj + '' except: return False else: return True -- http://mail.python.org/mailman/listinfo/python-list