On 3/9/23 14:10, Ihor Radchenko wrote:
Zelphir Kaltstahl <zelphirkaltst...@posteo.de> writes:
~~~~START~~~~
#+name: python-imports
#+begin_src python :python /usr/bin/python3 :results output replace drawer :var
x=4
import math
y = math.sqrt(x)
# print(y)
#+end_src
#+name: python-usage
#+begin_src python :python /usr/bin/python3 :return :noweb strip-export
:results value replace drawer
<<python-imports>>
print("y: {}".format(y))
#+end_src
~~~~~END~~~~~
Unfortunately, this example does not seem to work at all, but for a different
reason:
It seems that using any Python source block with :var header args via :noweb
does not work, as it then behaves in the way, that it merely pasted the included
source block, without first putting in the :var values into the variables. I get
errors about those :var variables being undefined, of course, since they are on
the included source block, not on the including one:
~~~~START: *Org-Babel Error Output*~~~~
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
File "<stdin>", line 5, in main
NameError: name 'x' is not defined
[ Babel evaluation exited with code 1 ]
~~~~~END~~~~~
This is expected. Noweb includes the src block code without altering it.
See 16.11 Noweb Reference Syntax
We may probably clarify this in the manual. Would it be helpful?
I think it would be helpful. I merely tried Python, because it was at hand and
because I did not find ob-racket in M-x package-list RET and did not have
another Scheme installed. Cannot say, whether others find the behavior confusing
or not, but I imagine I would find it helpful, if it was mentioned in the docs.
--
repositories: https://notabug.org/ZelphirKaltstahl