emacs-orgmode
[Top][All Lists]
Advanced

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

[O] (9.2) Noweb syntax not understood in Python blocks


From: Emmanuel Charpentier
Subject: [O] (9.2) Noweb syntax not understood in Python blocks
Date: Mon, 04 Feb 2019 12:29:31 +0100
User-agent: Evolution 3.30.4-1

Seen in `org-mode' version `9.2'.

Using `noweb' syntax works OK with `emacs-lisp':

┌────
│ #+name: a
│ #+begin_src emacs-lisp
│   (setq L (append L (list i)))
│ #+end_src
│ 
│ #+name: b
│ #+begin_src emacs-lisp :noweb yes :exports both
│   ;; Lisp version
│   (setq L nil)
│   (dotimes (i 5) <<a>>)
│   L
│ #+end_src
└────

This gives :

┌────
│ (setq L (append L (list i)))
└────

┌────
│ ;; Lisp version
│ (setq L nil)
│ (dotimes (i 5) )
│ L
└────

The `noweb' syntax also works with `Sage' (a symbolic maths oriented
Python derivative):

┌────
│ #+name: Aaarghhh
│ #+begin_src sage
│   L.append(i)
│ #+end_src
│ 
│ #+name: Berde
│ #+begin_src sage :noweb yes :exports both
│   ## Python version
│   L=[]
│   for i in range(1,6):
│       <<Aaarghhh>>
│   L
│ #+end_src
└────

wich gives :

┌────
│ L.append(i)
└────

┌────
│ ## Sage version
│ L=[]
│ for i in range(1,6):
│ 
│ L
└────

But using the same syntax in Python fails miserably:

┌────
│ #+name: Ah
│ #+begin_src python
│   L.append(i)
│ #+end_src
│ 
│ #+name: Beee
│ #+begin_src python :noweb yes :exports both
│   ## Python version
│   L=[]
│   for i in range(1,6):
│       <<Ah>>
│   L
│ #+end_src
└────

┌────
│ L.append(i)
└────

┌────
│ ## Python version
│ L=[]
│ for i in range(1,6):
│     <<Ah>>
│ L
└────

┌────
│ []
└────


It *seems* that the "Ah" block is not expanded.

The code itself should be sound *if* it expanded:

┌────
│ #+name: B0
│ #+begin_src python :exports both
│   L=[]
│   for i in range(1,6):
│       L.append(i)
│   L
│ #+end_src
└────

┌────
│ L=[]
│ for i in range(1,6):
│     L.append(i)
│ L
└────

━━━━━━━━━━━━━━━
 1  2  3  4  5 
━━━━━━━━━━━━━━━

During the compilation of the source of this mail, the following is
printed in the `*Python*' buffer:

┌────
│ >>> L.append(i)
│ >>> 
│ >>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_))
│ >>> 
│ >>> 
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>> ## Python version
│ ... L=[]
│ >>> for i in range(1,6):
│ ...     <<Ah>>
│   File "<stdin>", line 2
│     <<Ah>>
│      ^
│ SyntaxError: invalid syntax
│ >>> 
│ >>> L
│ []
│ >>> 
│ >>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_))
│ >>> 
│ >>> 
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>> L=[]
│ >>> for i in range(1,6):
│ ...     L.append(i)
│ ... 
│ >>> L
│ [1, 2, 3, 4, 5]
│ >>> 
│ >>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_))
│ >>> 
│ >>> 
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>> 
└────

The source code of this mail is attached.

--
Emmanuel Charpentier

Attachment: PythonNowebProblem.org
Description: Text document


reply via email to

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