Should probably use `io.open(filename, 'w', encoding='utf-8')` to get the unicode right.