Thanks for the reply.
Well, I have code similar to yours and the codecs module is
part of the distribution.
I find strange that with an iso-8859-1 encoding everything is ok, while
using cp1252 I got something like
Traceback (most recent call last):
File "<psi-last-command>", line 1, in ?
File "C:\jm\jmpy\psi\psi64beta3ansi\dist\a.py", line 1
SyntaxError: 'unknown encoding: cp1252' (a.py, line 1)
I repeat, this happens only in the exe version.
Maybe the problem lies in py2exe. Packing an exe with cp1252 encoded scripts
fails, while "iso-5589-1" works.
Jean-Michel Fauth, Switzerland
···
-----
Jean-Michel Fauth wrote:
I'm tweaking psi (psi.exe) and attempting to get rid
of the .cfg file, which hold the encoding information
for the small embeded psi editor.
I'm trying to get this info from the user platform.
There are several ways:(1) sys.getpreferredencoding()
(2) locale.getdefaultencoding()[1]
(3) wx.GetDefaultPyEncoding()Which one is the best/safest to use?
The question may look strange, I have to face a problem.
When running psi as script (1), (2), (3) return 'cp1252'
on my platform.
Once the app is packed with py2exe, (1) and (2) return
'cp1252', while (3) returns 'ascii'! Are (2) and (3) not
supposed to return identical values?
No, they should be the same as long as the value of (2) is recognized as
an encoding that the codecs module can find. Here is the code that sets
(3):
import sys as _sys
...
default = _sys.getdefaultencoding()
if default == 'ascii':
import locale
import codecs
try:
default = locale.getdefaultlocale()[1]
codecs.lookup(default)
except (ValueError, LookupError, TypeError):
default = _sys.getdefaultencoding()
del locale
del codecs
if default:
wx.SetDefaultPyEncoding(default)
del default
Perhaps you didn't tell py2exe to include the encodings package?