[IPython-User] file magic and unicode encoding

Thomas Kluyver takowl@gmail....
Wed Apr 10 11:17:47 CDT 2013


On 10 April 2013 15:55, epi <massimodisasha@gmail.com> wrote:

> SyntaxError: Non-ASCII character '\xc2' in file esadict.py on line 4, but
> no encoding declared; see http://www.python.org/peps/pep-0263.html for
> details
>
>
>  seems that %%file is saving without unicode encoding
> is it possible to specify the encoding to %%file ?
>

It's saving the text you give it. But without an encoding declaration, your
file is not valid in Python 2. The first or second line needs to look like:

# coding: utf-8

The %save magic, which is designed for Python code, adds this
automatically. But the %%file magic is for writing arbitrary text, so it
doesn't check or change the text before saving it.

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20130410/688f66d9/attachment.html 


More information about the IPython-User mailing list