Add coding header when notebook exported to .py file. #1158

merged 5 commits into from Dec 15, 2011


None yet

3 participants


Closes gh-1156

We probably want to strip the encoding declaration out when we load a .py file, as well. I'll add that to this PR.

@fperez fperez commented on an outdated diff Dec 15, 2011
@@ -111,7 +114,7 @@ class PyWriter(NotebookWriter):
def writes(self, nb, **kwargs):
lines = []
- lines.extend([u'# <nbformat>2</nbformat>',''])
+ lines.extend([u'# coding: utf-8', u'# <nbformat>2</nbformat>',''])
fperez Dec 15, 2011 Member

I think this should be done in two separate lines. Let' s not mix encoding with nbformat info. Instead, initialize the lines list with the encoding declaration:

lines = ['# coding: utf-8'']
# rest of the code as it was before this PR



Looks good to me, is there any benefit to # -*- coding: utf-8 -*- as Fernando originally suggested over # coding: utf-8 ?

@fperez fperez merged commit 688cc09 into ipython:master Dec 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment