On Sun, Aug 30, 2009 at 2:42 PM, Edward K. Ream<[email protected]> wrote:
> encoded strings on output. Of course, this leaves unanswered the essential
> question of what encodings to use when reading or writing! This is a
> complicated subject and it depends on what files are being read or written.
I think the file handling in leo is currently ok - it doesn't rely in
defaultencoding.
> something about Leo's encodings, you must explain in detail how Leo's code
> could be improved. Generalities are useless: I have to have some plan for
> making what presumably would be substantial changes to Leo's code. Better
> yet, I would like to see a branch that handles encodings in a better way.
We should attempt minizing the calls to toUnicode and the likes, but
that can wait.
> It's possible that major improvements can be made now. It is even more
> likely that improvements can be made when moving to Python 3.x. However,
> the notion that setting sys.setdefaultencoding('utf-8') in sitecustomize.py
> is somehow "evil" does not make sense to me. Indeed, without this setting,
> print(x), where x is a non-ascii character, produces byte hash. With this
> setting, all works as expected. This is a strange kind of evil.
You need to use sys.stdin.encoding to encode unicode to an encoding
that can be displayed on terminal. Though, even printing byte garbage
is better than compromising the integrity of the whole code (which is
what defaultencoding does), since printing is used only for debug
stuff anyway.
I think using sys.stdin.encoding, and not advertising
sys.setdefaultencoding as a solution to anything are the only concrete
things that need to be done.
The "evil" of sys.setdefaultencoding is that it appears to solve some
problems, while it only sweeps them under the rug (and postpones
actually fixing the bugs). The actual fix needed for print is
sys.stdin.encoding. If it didn't work at all, people would be forced
to fix their code properly, and general consensus is that it should
never have been implemented in Python (but they can't remove it now).
--
Ville M. Vainio
http://tinyurl.com/vainio
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---