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

Merged
merged 5 commits into from Dec 15, 2011

Conversation

Projects
None yet
3 participants
@takluyver
Member

takluyver commented Dec 15, 2011

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.

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>',''])

This comment has been minimized.

@fperez

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
@fperez

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
@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Dec 15, 2011

Member

Updated.

Member

takluyver commented Dec 15, 2011

Updated.

@bfroehle

This comment has been minimized.

Show comment
Hide comment
@bfroehle

bfroehle Dec 15, 2011

Contributor

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

Contributor

bfroehle commented Dec 15, 2011

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

fperez added a commit that referenced this pull request Dec 15, 2011

Merge pull request #1158 from takluyver/nbpy-encoding-declaration
Add coding header when notebook exported to .py file.

Closes gh-1156, also strips the encoding declaration out when we load a .py file.

@fperez fperez merged commit 688cc09 into ipython:master Dec 15, 2011

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

Merge pull request #1158 from takluyver/nbpy-encoding-declaration
Add coding header when notebook exported to .py file.

Closes gh-1156, also strips the encoding declaration out when we load a .py file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment