Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread marc . vanhoomissen
Hello,

This very simple program runs well on windows 7

# -*- utf8 -*-
print('Réussi')

But, when I start the vrey same file on Linux (ubuntu 14), I got:

Traceback (most recent call last):
  File /partages/bureau/PB/Dev/Python3/test.py, line 2, in module
print('R\xe9ussi')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: 
ordinal not in range(128)

What should i do to let the same program run on both OS, without changes?

Thank you for your answer

Marc Vanhoomissen
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread Vincent Vande Vyvre

Le 14/08/2014 14:35, marc.vanhoomis...@gmail.com a écrit :

Hello,

This very simple program runs well on windows 7

# -*- utf8 -*-
print('Réussi')

But, when I start the vrey same file on Linux (ubuntu 14), I got:

Traceback (most recent call last):
   File /partages/bureau/PB/Dev/Python3/test.py, line 2, in module
 print('R\xe9ussi')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: 
ordinal not in range(128)

What should i do to let the same program run on both OS, without changes?

Thank you for your answer

Marc Vanhoomissen

No problem on Ubuntu

Python 3.2.3 (default, Feb 27 2014, 21:33:50)
[GCC 4.6.3] on linux2
Type help, copyright, credits or license for more information.
 print(Réussi)
Réussi

Are you really using Python 3 ?

$ python3 test.py
--
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread YBM

Le 14/08/2014 14:35, marc.vanhoomis...@gmail.com a écrit :

Hello,

This very simple program runs well on windows 7

# -*- utf8 -*-
print('Réussi')

But, when I start the vrey same file on Linux (ubuntu 14), I got:

Traceback (most recent call last):
   File /partages/bureau/PB/Dev/Python3/test.py, line 2, in module
 print('R\xe9ussi')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: 
ordinal not in range(128)

What should i do to let the same program run on both OS, without changes?


the correct comment line should be : # -*- encoding: utf-8 -*-
and it could be usefull to begin with #!/usr/bin/env python
or #!/usr/bin/env python3 :

$ cat  réussi.py
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
print('Réussi');
^D
$ chmod +x réussi.py
$ ./réussi.py
Réussi
$ python réussi.py
Réussi


--
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread marc . vanhoomissen
Hello YBM,
I tried your suggestions, without improvement.
Further, see my answer to Vincent Vande Vyre
Thanks anyway.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread marc . vanhoomissen
Le jeudi 14 août 2014 15:22:52 UTC+2, Vincent Vande Vyvre a écrit :
 Le 14/08/2014 14:35, marc.vanhoomis...@gmail.com a �crit :
 
  Hello,
 
 
 
  This very simple program runs well on windows 7
 
 
 
  # -*- utf8 -*-
 
  print('R�ussi')
 
 
 
  But, when I start the vrey same file on Linux (ubuntu 14), I got:
 
 
 
  Traceback (most recent call last):
 
 File /partages/bureau/PB/Dev/Python3/test.py, line 2, in module
 
   print('R\xe9ussi')
 
  UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 
  1: ordinal not in range(128)
 
 
 
  What should i do to let the same program run on both OS, without changes?
 
 
 
  Thank you for your answer
 
 
 
  Marc Vanhoomissen
 
 No problem on Ubuntu
 
 
 
 Python 3.2.3 (default, Feb 27 2014, 21:33:50)
 
 [GCC 4.6.3] on linux2
 
 Type help, copyright, credits or license for more information.
 
   print(R�ussi)
 
 R�ussi
 
 
 
 Are you really using Python 3 ?
 
 
 
 $ python3 test.py

Actually, when I try using a terminal, it works:
$ python3 test.py
Réussi

But when I issue the same command using webmin (v. 1.700 - shell command), I 
got:
 python3 test.py
Traceback (most recent call last):
  File test.py, line 2, in module
print('R\xe9ussi')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: 
ordinal not in range(128)

So, I guess it is merely a problem of webmin.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread Mark Lawrence

On 14/08/2014 15:04, marc.vanhoomis...@gmail.com wrote:

Hello YBM,
I tried your suggestions, without improvement.
Further, see my answer to Vincent Vande Vyre
Thanks anyway.



I'm pleased to see that you have answers.  In return would you please 
quote the context.  Could you also access this list via 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread Anssi Saari
marc.vanhoomis...@gmail.com writes:

 What should i do to let the same program run on both OS, without changes?

You'd want to set the locale on your Ubuntu box to a UTF8 locale. On
the command line you'd run sudo dpkg-reconfigure locales and proceed
from there, but I guess there might be gooey way to do that too.

But really, it's a Linux configuration question, not a Python question.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread Vincent Vande Vyvre

Le 14/08/2014 15:31, YBM a écrit :

Le 14/08/2014 14:35, marc.vanhoomis...@gmail.com a écrit :

Hello,

This very simple program runs well on windows 7

# -*- utf8 -*-
print('Réussi')

But, when I start the vrey same file on Linux (ubuntu 14), I got:

Traceback (most recent call last):
   File /partages/bureau/PB/Dev/Python3/test.py, line 2, in module
 print('R\xe9ussi')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in 
position 1: ordinal not in range(128)


What should i do to let the same program run on both OS, without 
changes?


the correct comment line should be : # -*- encoding: utf-8 -*-
and it could be usefull to begin with #!/usr/bin/env python
or #!/usr/bin/env python3 :

$ cat  réussi.py
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
print('Réussi');
^D
$ chmod +x réussi.py
$ ./réussi.py
Réussi
$ python réussi.py
Réussi



Nothing to do with the file encoding.

... if the OP use really Python 3
--
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread YBM

Le 14/08/2014 16:04, marc.vanhoomis...@gmail.com a écrit :

Hello YBM,
I tried your suggestions, without improvement.
Further, see my answer to Vincent Vande Vyre
Thanks anyway.


This is indeed very surprising. Are you sure that you
have *exactly* this line at the first or second (not
later !) line of your script :

# -*- encoding: utf-8 -*-

if a single caracter differs, it would fail.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread Steven D'Aprano
YBM wrote:

 Le 14/08/2014 16:04, marc.vanhoomis...@gmail.com a écrit :
 Hello YBM,
 I tried your suggestions, without improvement.
 Further, see my answer to Vincent Vande Vyre
 Thanks anyway.
 
 This is indeed very surprising. Are you sure that you
 have *exactly* this line at the first or second (not
 later !) line of your script :
 
 # -*- encoding: utf-8 -*-
 
 if a single caracter differs, it would fail.

That's not correct. The encoding declaration is very flexible. Any of these
will be accepted:

# This file uses the encoding: utf_8
# coding=UTF-8
# -*- coding: utf8 -*-
# vim: set fileencoding=utf-8 :
# Uses encoding:utf8
# I want my encoding=UtF_8 okay!
 textencoding=  UTf-8 blah blah blah

and many, many other varieties. The rules are:

(1) It must be a comment;

(2) It must be in the first or second line of the file;

(3) It must match the regular expression rcoding[:=]\s*([-\w.]+)


However, just because you declare the file to be UTF-8, doesn't mean it
*actually is* UTF-8. If your text editor is configured to use (say)
Latin-1, a UTF-8 encoding declaration will just give you garbage.

* Fix your system to use UTF-8 by default.

* Fix your editor to use UTF-8.

* Add a UTF-8 encoding declaration.

And then things should work.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread Peter Otten
marc.vanhoomis...@gmail.com wrote:

 Le jeudi 14 août 2014 15:22:52 UTC+2, Vincent Vande Vyvre a écrit :

 Are you really using Python 3 ?

 $ python3 test.py
 
 Actually, when I try using a terminal, it works:
 $ python3 test.py
 Réussi
 
 But when I issue the same command using webmin (v. 1.700 - shell command),
 I got:
 python3 test.py
 Traceback (most recent call last):
   File test.py, line 2, in module
 print('R\xe9ussi')
 UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in
 position 1: ordinal not in range(128)
 
 So, I guess it is merely a problem of webmin.

I have no idea how that might interact with webmin, but you could try to set 
the environment variable

PYTHONIOENCODING=utf-8


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to run print('Réussi') on windows and on linux

2014-08-14 Thread Ian Kelly
On Thu, Aug 14, 2014 at 9:21 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 YBM wrote:

 Le 14/08/2014 16:04, marc.vanhoomis...@gmail.com a écrit :
 Hello YBM,
 I tried your suggestions, without improvement.
 Further, see my answer to Vincent Vande Vyre
 Thanks anyway.

 This is indeed very surprising. Are you sure that you
 have *exactly* this line at the first or second (not
 later !) line of your script :

 # -*- encoding: utf-8 -*-

 if a single caracter differs, it would fail.

 That's not correct. The encoding declaration is very flexible. Any of these
 will be accepted:

 # This file uses the encoding: utf_8
 # coding=UTF-8
 # -*- coding: utf8 -*-
 # vim: set fileencoding=utf-8 :
 # Uses encoding:utf8
 # I want my encoding=UtF_8 okay!
  textencoding=  UTf-8 blah blah blah

 and many, many other varieties. The rules are:

 (1) It must be a comment;

 (2) It must be in the first or second line of the file;

 (3) It must match the regular expression rcoding[:=]\s*([-\w.]+)


 However, just because you declare the file to be UTF-8, doesn't mean it
 *actually is* UTF-8. If your text editor is configured to use (say)
 Latin-1, a UTF-8 encoding declaration will just give you garbage.

 * Fix your system to use UTF-8 by default.

 * Fix your editor to use UTF-8.

 * Add a UTF-8 encoding declaration.

 And then things should work.

And apart from all of that, if the OP is really using Python 3 then
UTF-8 is the default source encoding anyway.
-- 
https://mail.python.org/mailman/listinfo/python-list