double newline from %loadpy in python notebook (at least on mac) #1204

Closed
piti118 opened this Issue Dec 24, 2011 · 3 comments

2 participants

@piti118

I suspect that it double count /r/n as two new lines. When I use %loadpy from python notebook(from stable 0.12) I expect something like

import pickle
from itertools import product
#get tmp.pck from prepareplotdata.py
f = open('tmp.pck')
m = pickle.load(f)

But I got something like

import pickle

from itertools import product

#get tmp.pck from prepareplotdata.py

f = open('tmp.pck')

m = pickle.load(f)
@piti118

Up on closer inspection it is the server side this is what I got Notebook.handle_shell_reply in e.data

{"parent_header":
  {"username":"username","msg_id":"49C2620FD9F34A4FAD75D5655CC7415E",
  "msg_type":"execute_request",
  "session":"439FD9883D22482098055D869FC61668"},
"msg_type":"execute_reply",
"msg_id":"a7f8a644-4959-470b-bedf-cdb7fdc58e90",
"content":
  {"status":"ok",
   "execution_count":10,
   "user_variables":{},
   "payload":
      [{"text":"#single new line after this\n\n#double new line after this\n\n\n\n#triple newline after this\n\n\n\n\n\n#no newline at the end",
       "source":"IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input"}],
   "user_expressions":{}},
"header":
  {"username":"kernel",
   "session":"e49e9d26-4fdc-419d-b51d-364299bdc070",
   "msg_id":"a7f8a644-4959-470b-bedf-cdb7fdc58e90",
   "msg_type":"execute_reply"}
}

1 new line got converted into 2 new lines
2 new lines got converted into 4 new lines
3 new lines got converted into 6 new lines

@minrk
IPython member

Argh - I know exactly what caused this, and it it affects %loadpy from local files in all contexts. See PR #1207 for a fix.

@piti118

Thanks that does the job :)

@piti118 piti118 closed this Dec 24, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment