Apparently we can set the encoding of a python source file with a
comment like:
# -*- coding: utf_8 -*-
at the very top of the file (It seems like it has to be pretty much the
first line).
Are there any comments about automatically adding this (or utf_16?) to
the top of all of the notebook files?
If there are no comments, I can post a patch for the notebook right away.
Your example works with the above magic comment as the first line of a
python file, but does not work if that comment is moved down one line.
Jason
Please definitely add this. Make a trac ticket asap for it. Thanks!!
You can also use the codecs module to handle this:
codecs.open('stuff.txt','wb','utf-8')
opens the file for writing with this encoding in mind.
didier
Is this better? The patch at #2399 does the magic comment trick. That
way, the encoding is part of the file, so the file is valid python in
and of itself.
Jason
I think your solution at #2399 is better.
William
Does someone want to review the patch positively? Maybe someone can
even convince mabshoff to apply it to 2.10.3 :)
Now we can make a demo with a notebook that has some very weird utf8
characters in it to show how Sage reaches out to the world via the web
interface (well, now=after patch is applied).
Something with very different-looking characters would be a nice visual
demonstration, like thai or cambodian or chinese or japanese characters.
Jason
Frankly I don't know (and didn't realize you had already posted the
patch). Unless python3.0's internals change for reading files, yours
should work.
didier
>
>
>
> Jason
>
>
> >
>