From: edgar@openmail.cc
To: emacs-orgmode@gnu.org
Subject: org-babel-expand-src-block v.s. org-babel-execute-src-block with Python
Date: Thu, 31 Aug 2017 23:27:20 +0000 [thread overview]
Message-ID: <1eb76c9a61ff015bcda88a4fa7d197db@openmail.cc> (raw)
[-- Attachment #1: Type: text/plain, Size: 543 bytes --]
Hello,
I have noticed that doing C-c C-v v (org-babel-expand-src-block) and C-c
C-c (org-babel-execute-src-block) yield different results in Python. I
have attached a file with a MWE and a couple of questions to avoid
clutter in the mailing list. Thank you in advance :) .
-------------------------------------------------
ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!
[-- Attachment #2: t.org --]
[-- Type: text/plain, Size: 1677 bytes --]
I open emacs with ~emacs -Q~
#+BEGIN_SRC emacs-lisp :results none
(org-babel-do-load-languages
'org-babel-load-languages
'((python . t)
(emacs-lisp . t)
(org . t)))
#+END_SRC
* This block works all the time
#+BEGIN_SRC python :python python3 :session
import numpy as np
for i in [1, 2, 3]:
a = i
print(a)
a
#+END_SRC
#+RESULTS:
: 3
* My Python 3 block:
#+BEGIN_SRC python :python python3 :session
import numpy as np
for i in [1, 2, 3]:
# Comment
a = i
print(a)
a
#+END_SRC
#+RESULTS:
* What happens with C-c C-c:
If I do C-c C-c in the block, I get this in the *Python* buffer:
#+BEGIN_EXAMPLE
>>> import numpy as np
>>> for i in [1, 2, 3]:
... # Comment
...
File "<stdin>", line 3
^
IndentationError: expected an indented block
a = i
>>>
File "<stdin>", line 1
a = i
^
IndentationError: unexpected indent
>>> print(a)
>>>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> open('/tmp/babel-112622VJ/python-112621jw', 'w').write(str(_))
>>>
20
>>>
>>> 'org_babel_python_eoe'
>>> 'org_babel_python_eoe'
>>>
#+END_EXAMPLE
* What happens with C-c C-v v C-c C-c
If I do C-c C-v v C-c C-c in the block, I get this in the *Python* buffer
#+BEGIN_EXAMPLE
>>> 3
>>>
#+END_EXAMPLE
* What happens with C-c ' C-c C-c
If I do C-c ' C-c C-c in the block, I get this in the *Python* buffer
#+BEGIN_EXAMPLE
>>> 3
>>>
#+END_EXAMPLE
* Question:
1. Is this the expected behaviour?
2. Is there a way to get ~#+RESULTS:~ with C-c C-c directly for this kind of blocks?
next reply other threads:[~2017-08-31 23:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-31 23:27 edgar [this message]
2017-09-03 12:23 ` org-babel-expand-src-block v.s. org-babel-execute-src-block with Python Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1eb76c9a61ff015bcda88a4fa7d197db@openmail.cc \
--to=edgar@openmail.cc \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.