From: Thomas Jollans on
On 08/02/2010 04:20 AM, Νίκος wrote:
> Also my greek print appear in funny encoding although i do use # -*-
> coding: utf-8 -*-

That's because you never told the web browser which encoding you're using.

Content-Type: text/html; charset=UTF-8
From: Thomas Jollans on
On 08/02/2010 10:13 PM, Νίκος wrote:
> Hello, any ideas?!

That's no way to treat a friendly volunteer mailing list like this one!


On 08/02/2010 02:32 PM, Νίκος wrote:
> As for the encoding Notepad++, which is what i use for an editor say
> its UTF-8 without BOM.
>
> Isn't this what i'm supposed to use?
>
> My Python scripts only containes english and greek letters, so i
> though usign UTF-8 is the way to go. No?! Please if you explain to me
> in greater detail!

As I said, you have to tell the browser what you're up to.

Also, I just checked the link (shame on me), and you're not using UTF-8
at all. You're using some weird Windows-xyz or ISO-8859-xyz Greek
codepage from the previous millennium. (which obviously my browser
didn't know, it thought you were using ISO-8859-1, because that's what
my browser does, which you weren't)


So: tripple-check that

* your file is <insert encoding here (aka UTF-8)>
* Python knows that
* the web browser knows that
From: Νίκος on
>On 2 Αύγ, 23:57, Thomas Jollans <thomas(a)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.
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?
c) print ''' Content-Type: text/html; charset=UTF-8 /n'''

Please explain to me as simple as you can because from the time with
php and perl encodings not only gave me a hard time but also caused my
program to produce internal server errors so i need to understand the
differences.

=========================
Also in the other problem with the cookie iam trying to set:
=========================
if os.environ.get('HTTP_COOKIE') and cookie.has_key('visitor') ==
'nikos': #if visitor cookie exist
print "Next time i will count you"
cookie['visitor'] = ( 'nikos', time() - 1 ) #this cookie will expire
now
else:
print "I wont be counting you any more"
cookie['visitor'] = ( 'nikos', time() + 60*60*24*365 ) #this cookie
will expire in an year
=========================

Why always the code block pertainign to 'else' get exectuted ane never
the code of 'if'
The idea is who ever runs 'koukos.py' to set/unset himself out of the
counter count so i need i way to set/unset the browser cookie!

Thanks you!
From: Chris Rebert on
2010/8/2 Νίκος <nikos.the.gr33k(a)gmail.com>:
>>On 2 Αύγ, 23:57, Thomas Jollans <thomas(a)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
From: Dave Angel on
��������������������������������� wrote:
>> On 2 Αύγ, 23:57, Thomas Jollans <thomas(a)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=F-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.
> 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?
> c) print ''' Content-Type: text/html; charset=F-8 /n'''
>
> Please explain to me as simple as you can because from the time with
> php and perl encodings not only gave me a hard time but also caused my
> program to produce internal server errors so i need to understand the
> differences.
>
> <snip>
There actually should be more than 3 things here. To understand the
distinctions you have to see who handles which data, and how.

a) a text editor takes keystrokes and cut/paste info and other data, and
produces a stream of (unicode) characters. It then encodes each of
those character into one or more bytes and saves it to a file. You have
to tell Notepad++ how to do that encoding. Note that unless it's saving
a BOM, there's no clue in the file what encoding it used.

b) The python compiler has to interpret the bytes it finds (spec. within
string literals and comments), and decode them into unicode for its own
work. It uses the 'coding:' comment to decide how to do this. But once
the file has been compiled, that comment is totally irrelevant, and ignored.

c1) Your python code has to decide how to encode its information when
writing to stdout. There are several ways to accomplish that.

c2) The browser sees only what was sent to stdout, starting with the
"Content-Type..." line. It uses that line to decide how to decode the
rest of the stream. Let me reemphasize, the browser does not see any of
the python code, or comments.

DaveA