gry
gry

Reputation: 13

Special characters in output are like �

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.

Upvotes: 0

Views: 204

Answers (3)

Roman Bodnarchuk
Roman Bodnarchuk

Reputation: 29727

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.

Upvotes: 0

Kirill
Kirill

Reputation: 3454

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

Upvotes: 0

Wooble
Wooble

Reputation: 89997

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.

Upvotes: 1

Related Questions