Last active
December 16, 2015 11:09
-
-
Save markusbaden/5425474 to your computer and use it in GitHub Desktop.
File cell magic in IPython fails on blank lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "file magic bug" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%%file no_blank.txt\n", | |
"line 1\n", | |
"line 2" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"Overwriting no_blank.txt\n" | |
] | |
} | |
], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"!cat no_blank.txt" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"line 1\r\n", | |
"line 2" | |
] | |
} | |
], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%%file with_blank.txt\n", | |
"line 1\n", | |
"\n", | |
"line 2" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "SyntaxError", | |
"evalue": "invalid syntax (<ipython-input-3-dc9d60bbbaec>, line 2)", | |
"output_type": "pyerr", | |
"traceback": [ | |
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-3-dc9d60bbbaec>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m line 2\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" | |
] | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%%file py_with_blank.py\n", | |
"print 'spam'\n", | |
"\n", | |
"print 'ham'" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"Overwriting py_with_blank.py\n", | |
"ham\n" | |
] | |
} | |
], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"!cat py_with_blank.py" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"print 'spam'" | |
] | |
} | |
], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"For reference, I use the development version of IPython and here is the last commit I pulled" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import IPython\n", | |
"import os\n", | |
"install_dir = os.path.split(IPython.__file__)[0]\n", | |
"cwd = %pwd\n", | |
"%cd -q $install_dir\n", | |
"!git show\n", | |
"%cd -q $cwd" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"commit 5e33c149a06b5cf9f9bb908230763bfee0181c1c\r\n", | |
"Merge: 28f7764 8c514aa\r\n", | |
"Author: Min RK <benjaminrk@gmail.com>\r\n", | |
"Date: Wed Apr 17 14:10:11 2013 -0700\r\n", | |
"\r\n", | |
" Merge pull request #3189 from juhasch/improve-completer\r\n", | |
" \r\n", | |
" fix notebook completer redraw on metakey press\r\n", | |
" \r\n", | |
" - set <select> tag to style=\"width: auto\" to fit complete autocomplete string in drop down menu\r\n", | |
" - handle special keys better, so shift, ctrl, pgup, pgdown et al work as expected in the drop down list (i.e. pgup/pgdown/home/end move selection, shift, ctrl, caps lock do not restart the drop down menu)\r\n", | |
"\r\n" | |
] | |
} | |
], | |
"prompt_number": 6 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment