Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19772

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <r.grimm@science-computing.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.060
X-Spam-Evidence '*H*': 0.89; '*S*': 0.01; 'reply- to:addr:comp.lang.python': 0.09; 'subject:string': 0.09; 'to:addr:comp.lang.python': 0.09; 'def': 0.13; 'cc:addr:python- list': 0.15; 'concise.': 0.16; 'rainer': 0.16; 'subject:variable': 0.16; '>>>': 0.18; 'cc:no real name:2**0': 0.21; 'subject:list': 0.21; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.25; 'cc:addr:python.org': 0.29; 'subject:?': 0.30; 'header:User- Agent:1': 0.33; 'received:209.85.212': 0.34; 'subject:How': 0.35; 'received:google.com': 0.37; 'subject:can': 0.37; 'received:209.85': 0.38; 'received:209': 0.39; 'subject:: ': 0.39; 'more': 0.61; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:googlegroups.com': 0.74; 'subject:content': 0.84; 'received:209.85.212.56': 0.91; 'received :mail-vw0-f56.google.com': 0.91
Newsgroups comp.lang.python
Date Wed, 1 Feb 2012 23:19:57 -0800 (PST)
In-Reply-To <mailman.5271.1328057831.27778.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=95.208.115.77; posting-account=F4Pl4woAAAA3GQgXD-VTbzEKduyArjBH
References <1328057052.56088.YahooMailNeo@web30601.mail.mud.yahoo.com> <mailman.5271.1328057831.27778.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
MIME-Version 1.0
Subject Re: How can I verify if the content of a variable is a list or a string?
From Rainer Grimm <r.grimm@science-computing.de>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To comp.lang.python@googlegroups.com
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.5346.1328167206.27778.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328167206 news.xs4all.nl 6859 [2001:888:2000:d::a6]:58309
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19772

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: How can I verify if the content of a variable is a list or a string? Terry Reedy <tjreedy@udel.edu> - 2012-01-31 19:56 -0500
  Re: How can I verify if the content of a variable is a list or a string? Rainer Grimm <r.grimm@science-computing.de> - 2012-02-01 23:19 -0800
  Re: How can I verify if the content of a variable is a list or a string? Rainer Grimm <r.grimm@science-computing.de> - 2012-02-01 23:19 -0800
    Re: How can I verify if the content of a variable is a list or a string? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 07:31 +0000

csiph-web