It works here if you remove the blank line between the headline
and the PROPERTIES block.
William McCoy writes:
Chuck,
Thanks very much for your response. I didn't know about those
options. When I
use C-c C-v C-i, I get the following:
Lang: python
Properties:
:header-args nil
:header-args:python nil
Header Arguments:
:cache no
:exports code
:hlines no
:noweb no
:results output replace
:session none
:tangle no
And C-c C-v C-v, shows that the import statements in the header
do not get
expanded into the code block.
So I am obviously doing something wrong. There appear to be no
typos or
misspellings and the org file containing the coded is exactly
this:
* Test of prologue header
:PROPERTIES:
:header-args:python+: :prologue "import numpy as np; import os"
:END:
#+BEGIN_SRC python :results output
print(np.__version__)
#+END_SRC
#+RESULTS:
My init file has no org babel header arguments defined.
I am using C-c C-v C-b or C-c C-v C-s to evaluate and I get
"Code block produced no output." in the mini-buffer.
If I use C-c C-c directly on the code block itself I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'np' is not defined
Is there something else I need to do to get babel to recognize
the header-args?
Thanks
On 8/7/20 12:51 PM, Berry, Charles wrote:
On Aug 7, 2020, at 8:39 AM, William McCoy <wdm8...@gmail.com>
wrote:
This use of :prologue appeared to me to be very useful. But
for some reason when I try it out it does not work for me. I
just get a message that the code block produced no output and
that 'np' is not defined. Just to check, when I put the
import statements directly within my code block it works fine.
I am running: Org mode version 9.3.7 (9.3.7-16-g521d7f-elpa
Any idea what I'm doing wrong?
It is sometimes useful to use C-c C-v C-i to see what header
args org has detected for a source block. Misspelled words
sometimes wreak havoc and invisible characters can cause real
pain.
Also, it helps to use C-c C-v C-v to to see the expanded code
block. When I do this with Kens' ECM, I get
import numpy as np; import os
print(np.__version__)
in the preview buffer.
HTH,
Chuck
On 8/6/20 2:12 PM, Ken Mankoff wrote:
Actual example:
* Prologue test
:PROPERTIES:
:header-args:python+: :prologue "import numpy as np; import
os"
:END:
#+BEGIN_SRC python :results output
print(np.__version__)
#+END_SRC
#+RESULTS:
: 1.18.4
On Wed, Aug 5, 2020 at 3:03 PM Ken Mankoff
<mank...@gmail.com> wrote:
What about using :pre or :prologue and setting it at the
header or document level?
Please excuse brevity. Sent from tiny pocket computer with
non-haptic-feedback keyboard.
On Wed, Aug 5, 2020, 14:22 George Mauer <gma...@gmail.com>
wrote:
Use case:
I'm using ob-racket but this would apply just as well to a
few other workflows I have with python or js.
I would like to write a helper function in a src block and
then automatically have access to it in other src blocks
further down the document. I don't really want a stateful
session (nor does ob-racket support sessions) so I
essentially want the equivalent of automatically including it
everywhere so I don't have to type it out all the time (and
have it screw up syntax coloring/indentation).
Is this currently possible? Does anyone have any ideas for
how to extend things so it is?
--
Thomas S. Dye
https://tsdye.online/tsdye