1

is there a method/package to use the following syntax to define and call a function?

#+NAME: retX
#+BEGIN_SRC python :var x=5
def retX (x):
    return x
#+END_SRC

... Some text later...

#+begin_src pyton
<<retX(x=6)>>
#+end_src

I am not a huge fan of being limited to

#+name: retX
#+begin_src python :var x=5
return x
#+end_src

...later...

#+call retX(x=6)

as I would like to be able to define a block such as

#+begin_src python :var x=5
<<retX(x)>> * <<retX(x=6)>>
#+end_src

and similiar.

2

With python you probably have to use a :session to get persistence between src blocks. I like :results output personally, and use print statements where I want them.

You can probably do this as follows:

#+BEGIN_SRC python :session :results output
def retX(x):
    return x
#+END_SRC

#+RESULTS:

#+BEGIN_SRC python  :session :results output
print(retX(x=6))
#+END_SRC

#+RESULTS:
: 6


#+BEGIN_SRC python  :session :results output :var x=5
print(retX(x) * retX(x=6))
#+END_SRC

#+RESULTS:
: 30
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.