AW: Re: Global unicode setting for Py2Exe

Yes, but hasattr(sys,"frozen") returns False instead of None. When not
freezing the package it does not work.
So this is my intro to the main script now:

#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

import sys
if hasattr(sys, "frozen"): #Py2Exe does not run Site.py
    sys.setdefaultencoding('iso-8859-1')
else: #The Python interpreter needs to reload the
function
    reload(sys)
    sys.setdefaultencoding('iso-8859-1')
    del sys.setdefaultencoding

import wx
.
.
.

Regards
Oliver

···

-----Ursprüngliche Nachricht-----
Von: news [mailto:news@sea.gmane.org] Im Auftrag von Thomas Heller
Gesendet: Mittwoch, 5. Mai 2004 17:52
An: wxpython-users@lists.wxwindows.org
Betreff: [wxPython-users] Re: Global unicode setting for Py2Exe

Oleg Deribas <rus43@kharkov.ukrtel.net> writes:

Oliver Walczak wrote:

I use a sitecustomize.py file to set the
internal string codec globally to "iso-8859-1". The XML parser in the
distributed project (generated with py2exe) fails with the well known

error

"ordinal not in range (128)" etc.

I use this hack (courtesy of Oleg Broytmann):

reload(sys)
sys.setdefaultencoding(codepage)

at the start of my application.

I do not know whether it is dangerous to replace the default encoding
afterwards or not. site.py which is normally run before the main
script, removes the setdefaultencoding method from the sys module.

The py2exe'd script doesn't run the code in site.py (same effect can be
achived in Python with the -S command line flag), so the
setdefaultencoding method is still present.

And I had no problems freezing a script and running the exe afterwards
by inserting this code at the top:

import sys
if hasattr(sys, "frozen") is not None:
    sys.setdefaultencoding("iso-8859-1")
    print "äöü".encode()

from wxPython.wx import *

class MyFrame(wxFrame):
    ....

The print "äöü".encode() statement shows that it works, I only had to
give the '-p encodings' command line flag to py2exe. This was with the
advanced sample provided with py2exe.

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

if hasattr(sys, "frozen") is not None:

Yes, but hasattr(sys,"frozen") returns False instead of None. When not

Sure, my fault. Originally the code was

if getattr(sys, "frozen", None) is not None:
    ....

and I wanted to replace the getattr by hasattr.
But you got the idea :wink:

Thomas