utf-8 coding sometimes it works, most of the time it don't work.

Stef Mientki stef.mientki at gmail.com
Wed Sep 22 04:15:30 EDT 2010


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 <eckhardt at satorlaser.com>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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100922/9260ea92/attachment-0001.html>


More information about the Python-list mailing list