%loadpy should cut out encoding declaration #1103

takluyver opened this Issue Dec 4, 2011 · 0 comments


None yet

1 participant


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

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 "<ipython-input-4-8226810be253>", line 0
SyntaxError: encoding declaration in Unicode string (<ipython-input-4-8226810be253>, line 0)
@takluyver takluyver closed this in 0c6c879 Dec 15, 2011
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
@takluyver takluyver Strip out encoding declaration in %loadpy
Closes gh-1103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment