[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Babel python question: use of ipython and %cpaste

From: Arun Persaud
Subject: Re: [O] Babel python question: use of ipython and %cpaste
Date: Tue, 03 Dec 2013 12:35:53 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0


On 12/03/2013 03:44 AM, Rasmus wrote:
>> [ipython in org mode]
> For Org you could do: 
>   (setq org-babel-python-command "ipython --no-banner --classic 
> --no-confirm-exit")
> You should now be able to do
> #+BEGIN_SRC python :results output
> %timeit 1+1

nice ;) that works well for me. Thanks!

Since I now have ipython as an interpreter, is there a way to have org
mode use %cpaste to copy the code into the python buffer?

That way empty lines would be handled correctly, e.g.

#+BEGIN_SRC python :results output :session
  for i in range(2):



would work. I got it to work using something like this

; use %cpaste to paste code into ipython in org mode
(defadvice org-babel-python-evaluate-session
  (around org-python-use-cpaste
          (session body &optional result-type result-params) activate)
  "add a %cpaste and '--' to the body, so that ipython does the right
  (setq body (concat "%cpaste\n" body "\n--"))
  (setq ad-return-value (replace-regexp-in-string "\\(^Pasting code;
enter '--' alone on the line to stop or use Ctrl-D\.[\r\n]:*\\)" ""

I also put a request in to have a %cpaste -q option to suppress output.
But I'm wondering if there is a better way of doing this...

thanks again


reply via email to

[Prev in Thread] Current Thread [Next in Thread]