On Wed, Mar 5, 2008 at 5:24 PM, Jason Grout <[EMAIL PROTECTED]> wrote: > > > dean moore wrote: > > When I was writing some other code this came out; finally decided to > > report it. Do the following > > in an online SAGE notebook: > > > > /1+1/ > > > > We get two. Now run the following: > > > > /# Limaçon > > 1+1 > > / > > Get: > > > > /Exception (click to the left for traceback): > > ... > > SyntaxError: Non-ASCII character '\xe7' in file > > /home/server2/sage_notebook/worksheets/dino/9/code/3.py on line 4, but > > no encoding declared; see http://www.python.org/peps/pep-0263.html for > > details > > > > Traceback (most recent call last): > > File "<stdin>", line 1, in <module> > > File "/home/server2/sage_notebook/worksheets/dino/9/code/3.py", line 4 > > SyntaxError: Non-ASCII character '\xe7' in file > > /home/server2/sage_notebook/worksheets/dino/9/code/3.py on line 4, but > > no encoding declared; see http://www.python.org/peps/pep-0263.html for > > details/ > > > > --- > > > > /Sacre bleu!/ It's in a comment! Looking at the error & the web site > > it may be a Python thing & untouchable. > > But can we get around this? Shouldn't our French friends (and countless > > others) be able to use SAGE? > > > 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?
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 > > 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 > > > > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---