Robin Dunn wrote:
jmf wrote:
> When one writes a standard Python script and run it with the Python
> interpreter, it is possible (sometimes mandatory) to specifiy an
> encoding information on top of the script that will be processed by
> Python. The encoding is the first thing, Python has to know before
> further processing.No problem here, the case is clear.
>
> Now I can not figure out how this encoding stuff is working, when
> one uses an application with an embedded Python interpreter?
> Assume I have an Python/wxPython application with an embedded
> interpreter - a derived class from InteractiveInterpreter - and
> I feed this interpreter with some code (text) coming from, let's say,
> a TextCtrl or a StyledTextCtrl, eg PyShell, it is surprisingly
> working well. In that case, how does the embedded interpreter know
> which encoding it should use? Will it use the encoding of the script
> in which it is defined / coded?
wx.py.interpreter.Interpreter has this in the push method:
# In case the command is unicode try encoding it
if type(command) == unicode:
try:
command = command.encode(wx.GetDefaultPyEncoding())
except UnicodeEncodeError:
pass # otherwise leave it alone
···
---
Well, I understand this. My "problem/question" is a little bit elsewhere.
If I push a str to the interpreter, it is working.
If I push an unicode to the interpreter, without any "special" encoding, it is
working too!
In other words, I never succeed to fall in the "except
UnicodeEncodeError:" case !
To be short: I do not understand, why it is working. Maybe, because
I'm staying in the char "code point" range < 256 ? However, the euro
sign is above 255 and is well intepreted.
Anyway, thanks for the reply. Will try to find the time for some
more tests.
Jean-Michel Fauth, Switzerland.