Setting default encoding to UTF-8 in Python

After a long struggle for fixing up an error thrown by my Python script, I finally figured out an easy way to do it.
As we know, Python's default encoding is ASCII (0-127), anything beyond that , Non-ASCII characters throws UnicodeEncode exception. To fix it up, we need to use UTF-8 encoding, which suits most of the characters.
The easiest way to do that is:
Go to your Python setup directory and then go to lib: C:\Python27\lib
Look for site.py file, used for site specific configuration
Edit it: Go to 'setencoding()' function and change the line: encoding = "ascii" to encoding = "utf-8"
That's it!

I don't know other implications of editing it right in site.py file but it worked for me, and I found it the easiest way to change the encoding!

Comments

Popular posts from this blog

SQL Injection in search field

File Upload through Null Byte Injection