how to test attribute existence of feedparser objects

HansPeter hanspeter.sloot at gmail.com
Thu Dec 8 04:34:09 EST 2011


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.

  d=feedparser.parse(url,handlers = [proxy])
  try:
    print "TITLE ",d.feed.title
  except:
    print "HAS NO TITLE"
  wc={}

Regards HansPeter



More information about the Python-list mailing list