Re: How can I verify if the content of a variable is a list or a string?

2012-02-01 Thread Steven D'Aprano
On Wed, 01 Feb 2012 23:19:57 -0800, Rainer Grimm wrote: > You can do it more concise. > def isListOrString(p): > ...return any((isinstance(p,list),isinstance(p,str))) Or even more concisely still: isinstance(p, (list, str)) -- Steven -- http://mail.python.org/mailman/listinfo/pyt

Re: How can I verify if the content of a variable is a list or a string?

2012-02-01 Thread Rainer Grimm
You can do it more concise. >>> def isListOrString(p): ...return any((isinstance(p,list),isinstance(p,str))) ... >>> listOrString("string") True >>> listOrString([1,2,3]) True >>> listOrString(2) False >>> listOrString(False) False Rainer -- http://mail.python.org/mailman/listinfo/python-lis

Re: How can I verify if the content of a variable is a list or a string?

2012-02-01 Thread Chris Angelico
On Wed, Feb 1, 2012 at 12:11 PM, Andres Soto wrote: > > okok, my mistake is that I was using string in place of str. Thank you!! > regards Tip: In the interactive interpreter, enter: >>> type("spam") In Python 2, it'll say "type" not "class", but same diff. It tells you there what the type is.

Re: How can I verify if the content of a variable is a list or a string?

2012-01-31 Thread Andres Soto
M >Subject: Re: How can I verify if the content of a variable is a list or a >string? > >On Wed, Feb 1, 2012 at 12:44 AM, Andres Soto wrote: >> Hi, >> I'm writing a function which receive a list which elements are strings or >> new lists (sublists) containing str

Re: How can I verify if the content of a variable is a list or a string?

2012-01-31 Thread Noah Hall
On Wed, Feb 1, 2012 at 12:44 AM, Andres Soto wrote: > Hi, > I'm writing a function which receive a list which elements are strings or > new lists (sublists) containing strings. > How can I verify if sone element of the list (which is contained in a > variable) is a list or a string? > I found the

Re: How can I verify if the content of a variable is a list or a string?

2012-01-31 Thread Terry Reedy
On 1/31/2012 7:44 PM, Andres Soto wrote: Hi, I'm writing a function which receive a list which elements are strings or new lists (sublists) containing strings. How can I verify if sone element of the list (which is contained in a variable) is a list or a string? I found the method isinstance(obje

How can I verify if the content of a variable is a list or a string?

2012-01-31 Thread Andres Soto
Hi, I'm writing a function which receive a list which elements are strings or new lists (sublists) containing strings. How can I verify if sone element of the list (which is contained in a variable) is a list or a string? I found the method isinstance(object,class) but I don't know which class