Fixed encoding issue

Replaced
f = open(filename, 'r+')
with
f = codecs.open(filename, 'r+', 'UTF-8')
to fix
'ascii' codec can't encode character u'\xfc' in position 150: ordinal not in range(128)