Re: utf-8 coding sometimes it works, most of the time it don't work.
hello Uli, thanks, I think you hit the nail on it's head, PyScripter indeed changes default encoding but .. On Wed, Sep 22, 2010 at 9:16 AM, Ulrich Eckhardt wrote: > Stef Mientki wrote: > > When running this python application from the command line ( or launched > > from another Python program), the wrong character encoding (probably > > windows-1252) is used. > > Rule #1: If you know the correct encoding, set it yourself. This > particularly applies to files you open yourself (use the codec module). In > the case of your program, I guess the stream with the faulty encoding is > stdin/stdout, who's encoding is guessed by Python, but which you can > override. Check sys.stdin.encoding. > None, So I guess it's using the windows default, which is windows-1252, and it's ReadOnly so I can't change it. Can you tell me how I change the default Python encoding, or how to set the encoding in Popen, this is the statement I use to launch my program subprocess.Popen ( [ 'python', Filename ] ) thanks, Stef Mientki > > > When I run this program from PyScripter ( either internal engine or > remote > > engine), MSHTML shows the correct character encoding, > > perfect! > > Interesting, I would say that PyScripter sets up the environment > differently, so that Python guesses a different encoding. Also make sure > both are calling the same Python, I get 'cp850' or 'US-ASCII' depending on > whether I call the native MS Windows Python or the Cygwin Python. > > > In the main file, and in the major files that constains strings I've > added > > the following 2 lines: > > # -*- coding: utf-8 -*- > > from __future__ import absolute_import, unicode_literals > > This shouldn't matter. This just tells Python that the sourcecode itself is > encoded in UTF-8 and that you want to use Unicode names in your string > literals, it doesn't affect the output of your program. > > Uli > > -- > Sator Laser GmbH > Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: utf-8 coding sometimes it works, most of the time it don't work.
Stef Mientki wrote: > When running this python application from the command line ( or launched > from another Python program), the wrong character encoding (probably > windows-1252) is used. Rule #1: If you know the correct encoding, set it yourself. This particularly applies to files you open yourself (use the codec module). In the case of your program, I guess the stream with the faulty encoding is stdin/stdout, who's encoding is guessed by Python, but which you can override. Check sys.stdin.encoding. > When I run this program from PyScripter ( either internal engine or remote > engine), MSHTML shows the correct character encoding, > perfect! Interesting, I would say that PyScripter sets up the environment differently, so that Python guesses a different encoding. Also make sure both are calling the same Python, I get 'cp850' or 'US-ASCII' depending on whether I call the native MS Windows Python or the Cygwin Python. > In the main file, and in the major files that constains strings I've added > the following 2 lines: > # -*- coding: utf-8 -*- > from __future__ import absolute_import, unicode_literals This shouldn't matter. This just tells Python that the sourcecode itself is encoded in UTF-8 and that you want to use Unicode names in your string literals, it doesn't affect the output of your program. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
utf-8 coding sometimes it works, most of the time it don't work.
hello, I've a pyjamas application (python to javascript translator), that can be run (as pure python) in MSHTML (IE Com interface) . When running this python application from the command line ( or launched from another Python program), the wrong character encoding (probably windows-1252) is used. When I run this program from PyScripter ( either internal engine or remote engine), MSHTML shows the correct character encoding, perfect! In the main file, and in the major files that constains strings I've added the following 2 lines: # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals >From the Pyjamas and PyScripter group I've no answer untill now. any clues where to look for the problem ? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list