Avoiding use of .encode() in rss2html My concern with this code is the excessive use of .encode('utf-8').  Any advice on refining these functions would be very helpful.

rss2html GitHub repo

#!/usr/bin/env python

""" Simple rss to html converter """

__version__ = "0.0.1"
__author__ = "Ricky L Wilson"

from feedparser import parse as parsefeed
import StringIO


def entry2html(**kwargs):
    """ Format feedparser entry """
    title = kwargs['title'].encode('utf-8')
    link = kwargs['link'].encode('utf-8')
    description = kwargs['description'].encode('utf-8')
    template = """
    &lt;h2 class='title'&gt;{title}&lt;/h2&gt;
    &lt;a class='link' href='{link}'&gt;{title}&lt;/a&gt;
    &lt;span class='description'&gt;{description}&lt;/span&gt;
    """
    return template.format(title=title, link=link, description=description)


def convert_feed(**kwargs):
    """ Main loop """
    out = StringIO.StringIO("")
    for entry in parsefeed(kwargs['url']).entries:
        title = entry['title']
        link = entry['link']
        description = entry['description']
        print &gt;&gt;out, entry2html(title=title, link=link,
                                description=description)
    return out.getvalue()

print convert_feed(url='http://stackoverflow.com/feeds')
Work in Unicode and encode at the last moment:

def entry2html(**kwargs):
    """ Format feedparser entry """
    template = u"""
    &lt;h2 class='title'&gt;{title}&lt;/h2&gt;
    &lt;a class='link' href='{link}'&gt;{title}&lt;/a&gt;
    &lt;span class='description'&gt;{description}&lt;/span&gt;
    """
    return template.format(**kwargs)

def convert_feed(**kwargs):
    """ Main loop """
    out = u'\n'.join(entry2html(**entry) 
                    for entry in parsefeed(kwargs['url']).entries)
    return out.encode('utf-8')


You can pass entry directly as format does not mind extra keyword arguments. StringIO is not necessary for simple concatenation of strings.