How to print non-ascii characters to file in Python 2.7
I'm trying to obfuscate some javascript by altering their character codes, but I've found that I can't correctly print characters outside of a certain range, in Python 2.7. For example, here's what I'm trying to do: f = open('text.txt','w') f.write(unichr(510).encode('utf-8')) f.close() I can't write unichr(510) because it says the ascii codec is out of range. So I encode it with utf-8. This turns a single character u'\u01fe' into two '\xc7\xbe' . Now, in javascript, it's easy to get the symbol for the character code 510: String.fromCharCode(510) Gives the single character: Ǿ What I'm getting