session在org源代码中的应用

从文档中读到 Using session的部分The Org Manual](The Org Manual),

For example, ‘:session STRING’ names it ‘STRING’. If ‘session’ has no value, then the session name is derived from the source language identifier. Subsequent blocks with the same source code language use the same session.

想实现下面的代码

#+begin_src python :session test
a=1
#+end_src

#+RESULTS:

#+begin_src python :session test
print(a)
#+end_src

#+RESULTS:

两段代码在同一个session下, 分别执行C-c C-c之后, 为什么result没有输出呢?

第二个 source block 改一下

#+begin_src python :session test :results output
print(a)
#+end_src

参考文档,results 参数的值

  • value Default. Functional mode. Result is the value returned by the last statement in the ‘src’ code block. Languages like Python may require an explicit return statement in the ‘src’ code block. Usage example: :results value.
  • output Scripting mode. Result is collected from STDOUT during execution of the code in the ‘src’ code block. Usage example: :results output.

也就是说默认是 value,对于 print 语句的结果是不输出的

1 个赞