Python equivalent of Common Lisp Macros?

dpapathanasiou denis.papathanasiou at gmail.com
Wed Nov 26 14:13:10 EST 2008


I'm using the feedparser library to extract data from rss feed items.

After I wrote this function, which returns a list of item titles, I
noticed that most item attributes would be retrieved the same way,
i.e., the function would look exactly the same, except for the single
data.append line inside the for loop.

In CL, I could simply write a macro, then replace the data.append line
depending on which attribute I wanted.

Is there anything similar in Python?

Here's the function:

def item_titles (feed_url):
    """Return a list of the item titles found in this feed url"""
    data = []
    feed = feedparser.parse(feed_url)
    if feed:
        if len(feed.version) > 0:
            for e in feed.entries:
                data.append(e.title.encode('utf-8'))
    return data



More information about the Python-list mailing list