I posted this on stackoverflow, one of my other favorite websites.

The most productive, efficient way to make UTF-8 work is to do the following.

Reconfigure the print statement to print utf-8 characters with a modification to the sys module at the includes of your modules.

import sys
sys.stdout.reconfigure(encoding='utf-8')

Then header area after print session variable, and before the print newline, then print html content.

print("Content-Type:text/html;charset=utf-8;")

Then in the html header of your html page, output the charset.

<meta charset="UTF-8">

Now you may print uft-8 characters in your html page.

print("string utf-8 characters, e.g., şö")

Though I find if translation is your intention, keeping a website in english most productive in my opinion, then include something like pyquery, phpquery and do string replacements with translated strings.

Happy Coding!

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *