Permalink
Browse files

Add encoding header to Python files downloaded from notebooks.

Closes gh-1156.
  • Loading branch information...
1 parent 2c683b7 commit faa2d7f91186f56e7b66fafc882c84c64ed5223a @bfroehle committed Dec 15, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 IPython/nbformat/v2/nbpy.py
@@ -40,6 +40,8 @@ def to_notebook(self, s, **kwargs):
for line in lines:
if line.startswith(u'# <nbformat>'):
pass
+ elif line.startswith(u'# -*-'):
+ pass
@bfroehle

bfroehle Dec 15, 2011

Owner

This prevents the encoding header from appearing in the notebook interface. Is this the desired behavior?

elif line.startswith(u'# <codecell>'):
cell = self.new_cell(state, cell_lines)
if cell is not None:
@@ -111,7 +113,9 @@ 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>',
+ u''])
for ws in nb.worksheets:
for cell in ws.cells:
if cell.cell_type == u'code':

0 comments on commit faa2d7f

Please sign in to comment.