ipython/ipython — Issue #1103: %loadpy should cut out encoding declaration
Author: takluyver
Created: 2011-12-04 23:09:27+00:00
State: open
Labels: prio-medium, status-active, type-bug, unicode

I noticed recently that doing %loadpy on a file with a `# coding: utf-8` magic comment causes a problem, because the compiler doesn't like encoding declarations in a unicode string. We should ideally detect this, use it to correctly decode the file ourselves, and then remove the encoding declaration from the code that appears.

Example session:

```
In [1]: print 123
123

In [2]: %save foo.py 1
The following commands were written to file `foo.py`:
print 123

In [3]: %loadpy foo.py

In [4]: # coding: utf-8
...: print 123
File "", line 0
SyntaxError: encoding declaration in Unicode string (, line 0)
```