amiralul · 2022-04-24 08:19
In *org-mode*, I'm using `#+name: var1` at the top of the code block to use the output of the code evaluation across the rest of the document, as `call_var1()`. And it works great.
What if I have a Python code block with multiple variables inside (`var2`, `var3` etc) that I would like to export and make them available across the rest of the document. How can I do that? Or at least to use the `var2`, `var3` etc variables in other Python code blocks?
[deleted] · 2022-04-24 09:50
[removed]
organic-bookworm · 2022-04-24 10:42
See sessions in the [org-mode](https://orgmode.org/manual/Environment-of-a-Code-Block.html#index-session_002c-header-argument) and [ob-python](https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html#orgf078b01) manuals.
>Sessions can be used to define functions, set up variables, and share code between source blocks.
#+begin_src python :results none :session
var2 = 2
var3 = 3
#+end_src
#+begin_src python :results output :session
print(var2+var3)
#+end_src
#+RESULTS:
: 5
amiralul · 2022-04-24 10:44
This is wonderful, thank you!