开发者

Special characters in output are like �

开发者 https://www.devze.com 2023-04-05 18:32 出处:网络
I have some .txt files which included Turkish characters. I prepared a HTML code and wanna include texts which are in my txt files. The processes are successful but the html files which are made by py

I have some .txt files which included Turkish characters. I prepared a HTML code and wanna include texts which are in my txt files. The processes are successful but the html files which are made by python have character problems(special characters seems like this: �)

I have tried add u before strings in python code but it did not work.

开发者_运维百科

txt files are made by python. actually they are my blog entries I got them using urrlib. Moreover, they have not character problems

thank you for your answers.


When you serve the content to a web browser, you need to tell it what encoding the file is in. Ideally, you should send a Content-type: HTTP header in the response with something like text/plain; charset=utf-8, where "utf-8" is replaced by whatever encoding you're actually using if it's not utf-8.

Your browser may also need to be set to use a unicode-aware font for displaying text files; if it uses a font that doesn't have the necessary glyphs, obviously it can't display them.


I think it isn't a Python question. Have you specified the document's character encoding?


You have to supply you html with something like the next:

<meta content="text/html; charset=UTF-8">

Replace UTF-8 with encoding used in .txt file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号