Trying to set a cookie within a python script

Chris Rebert clp2 at rebertia.com
Tue Aug 3 03:39:45 EDT 2010


2010/8/2 Νίκος <nikos.the.gr33k at gmail.com>:
>>On 2 Αύγ, 23:57, Thomas Jollans <thomas at jollans.com> wrote:
>
>> So: tripple-check that
>>
>>  * your file is <insert encoding here (aka UTF-8)>
>>  * Python knows that
>>  * the web browser knows that
>
> Thank you! i used print ''' Content-Type: text/html; charset=UTF-8 /
> n''' and it worked.
> I'am still pretty confused about the encodings.
>
> Please tell me the difference between 3 things.
>
> a) Asking Notepad++(my editor) to save all my python scripts as UTF-8
> without BOM.

That affects what encoding the text file comprising the source code
itself is in.

> b) Using this line '# -*- coding: utf-8 -*-' Isn't this line supposed
> to tell browser that the contents of this python script as in UTF-8
> and to handle it as such?

This tells Python what encoding the text file comprising the source
code itself is in.

> c) print ''' Content-Type: text/html; charset=UTF-8 /n'''

This tells the web browser what encoding the HTML you're sending it is
in. Said HTML is output by your Python script and must match the
encoding you specify in (c).

Unless you have Unicode string literals in the source code itself, (a)
and (b) don't matter much. (c) is quite crucial.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list