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

Merged
merged 5 commits into from Dec 15, 2011

Projects

None yet

3 participants

@takluyver
Member

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
IPython/nbformat/v2/nbpy.py
@@ -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
fperez Dec 15, 2011 IPython 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
@takluyver
Member

Updated.

@bfroehle

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