FAQ
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

Search Discussions

  • Ulrich Eckhardt at Sep 22, 2010 at 7:16 am

    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
  • Stef Mientki at Sep 22, 2010 at 8:15 am
    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
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20100922/9260ea92/attachment-0001.html>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 21, '10 at 9:08a
activeSep 22, '10 at 8:15a
posts3
users2
websitepython.org

2 users in discussion

Stef Mientki: 2 posts Ulrich Eckhardt: 1 post

People

Translate

site design / logo © 2022 Grokbase