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


Groups > comp.lang.python > #16816

Re: how to test attribute existence of feedparser objects

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!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:test': 0.05; 'attribute': 0.07; 'reason.': 0.07; 'am,': 0.12; 'exception': 0.12; 'library': 0.13; 'case.': 0.15; 'entries': 0.15; "'title'": 0.16; 'attribute?': 0.16; 'clause,': 0.16; 'feedparser': 0.16; 'title.': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'exists': 0.18; 'cc:no real name:2**0': 0.20; 'cheers,': 0.20; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'feeds': 0.23; 'cc:2**0': 0.24; 'function': 0.27; 'received:209.85.220': 0.27; 'skip:" 30': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'seem': 0.30; 'bare': 0.30; 'chris': 0.30; 'hi,': 0.32; 'thu,': 0.32; "won't": 0.33; 'there': 0.33; 'object': 0.33; 'test': 0.35; 'unless': 0.35; 'but': 0.37; 'received:google.com': 0.37; 'doing': 0.38; 'using': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'subject:how': 0.39; 'received:209': 0.40; 'difference': 0.40; '2011': 0.61; 'below': 0.63; 'mention.': 0.84; 'sender:addr:chris': 0.84; 'url:rebertia': 0.84; 'skip:d 50': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=HqAuLu49qbod2EuNT/wPPLehv7rw1EZq1ZNS989DIVo=; b=Qrg54aM77EYX9tu9Elnzl8MndHdCn+lrVOpSaWK8jdW1YHCP7XJD7eSk9TBOx/reb8 Y4sRt/BFBXeIklqq2nxywUib+nrp0O93/nWXEJ8qpGSKf3ONpW1PUrlO5HFc0zfEu8GB 9YAMc0ER+qK03s99dMdS+sEs4+NOtjxi7jX1c=
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <2e457709-b40a-4763-8a3b-0e0560e98ee1@n10g2000vbg.googlegroups.com>
References <2e457709-b40a-4763-8a3b-0e0560e98ee1@n10g2000vbg.googlegroups.com>
Date Thu, 8 Dec 2011 02:24:30 -0800
X-Google-Sender-Auth r9OWTktfVxC-I_52RShcO8CZGQg
Subject Re: how to test attribute existence of feedparser objects
From Chris Rebert <clp2@rebertia.com>
To HansPeter <hanspeter.sloot@gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
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>
Newsgroups comp.lang.python
Message-ID <mailman.3401.1323339874.27778.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323339874 news.xs4all.nl 6985 [2001:888:2000:d::a6]:34367
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16816

Show key headers only | View raw


On Thu, Dec 8, 2011 at 1:34 AM, HansPeter <hanspeter.sloot@gmail.com> wrote:
> Hi,
>
> While using the feedparser library for downloading RSS feeds some of
> the blog entries seem to have no title.
>
>  File "build\bdist.win32\egg\feedparser.py", line 382, in __getattr__
> AttributeError: object has no attribute 'title'
>
> Is there a way to test the existence of an attribute?
>
> I can use an exception but like below to see whether it exists but
> this is a clumsy way since the function has to return the title.

hasattr(obj, attr_name)
See docs.python.org/dev/library/functions.html#hasattr

That said, sounds like it won't make much difference in the particular
case you mention.
Also, never use a bare "except:" clause, unless you know what you're
doing and have a really good reason. Do "except AttributeError" in
this case.

Cheers,
Chris
--
http://rebertia.com

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


Thread

how to test attribute existence of feedparser objects HansPeter <hanspeter.sloot@gmail.com> - 2011-12-08 01:34 -0800
  Re: how to test attribute existence of feedparser objects Chris Rebert <clp2@rebertia.com> - 2011-12-08 02:24 -0800
  Re: how to test attribute existence of feedparser objects xDog Walker <thudfoo@gmail.com> - 2011-12-10 09:19 -0800
    Re: how to test attribute existence of feedparser objects Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-10 17:51 +0000

csiph-web