On Fri, Jul 22, 2011 at 9:22 AM, Dirk Scharff
<dirk.scharff@googlemail.com> wrote:
Hi
i just noticed that variables are assigned in the top of the exported code. That can be problematic in some situations:
#+source: the_test
#+begin_src python :var x=3 :tangle test.py :results output
from __future__ import division
print x
#+end_src
tangling results in:
x=3
from __future__ import division
print x
The problem with the result is simple:
SyntaxError: from __future__ imports must occur at the beginning of the file
To export this correctly I'd need the possibility to tell org-mode where the variables are supposed to be inserted. Is there a way to do this? I didn't find a keyword for this in the documentation.
For tangling: you could put from __future__ imports into the :shebang and use padline ":padline no", i.e.:
#+source: the_test
#+begin_src python :var x=3 :tangle test.py :results output :shebang from __future__ imports :padline no
print x
#+end_src
which results in
from __future__ imports
print x
Keep in mind, that I have NEVER used python (although I should...).
Cheers,
Rainer
A second problem I have at the moment lies with the execution of source-blocks in tables. What I'd like to do:
| argument | result |
| 1 | #ERROR |
| | |
#+TBLFM: $2=call_the_test(x=$<)
I guess I'm just doing something wrong here. Executing the #+Tblfm results in the error: "reference $< not found in buffer". How do I do the reference correctly in this case?
You can test both cases in the attached org-file.