Unicode iterator

By Filip Salomonsson; published on August 29, 2007. Tags: python unicode

Especially in python 2.4 and earlier, this little buddy can be a pretty useful companion when working with fileinput or file objects returned by urllib2. (fileinput in 2.5 can handle the decoding via the new openhook argument.)

def unicodeiter(iterable, encoding="utf-8"):
    for item in iterable:
        yield unicode(item, encoding)

Not exactly rocket science, but still.