简体   繁体   English

将串行函数输出重定向到结果

[英]Redirect sereral functions outputs to results

When work in source code of python,在 python 的源代码中工作时,

#+BEGIN_SRC python :session test :results output
print('testing1')
print('testing2')
#+END_SRC

#+RESULTS:
: testing1
: testing2

Set :results as output and then get 2 results,:results设置为 output 然后得到 2 个结果,

Try elisp试试 elisp

#+begin_src emacs-lisp  :results output
(+ 21 35 12 7)
(* 25 4 12)
#+end_src

#+RESULTS:

How could get elisp codes redirect outputs to results如何让 elisp 代码将输出重定向到结果

Those source blocks have different behaviour -- your python code prints to stdout while the elisp just evaluates expressions.这些源代码块具有不同的行为——您的 python 代码打印到stdout ,而 elisp 只计算表达式。

An equivalent elisp block might be一个等效的 elisp 块可能是

#+BEGIN_SRC elisp :results output
(princ (+ 21 35 12 7))
(print (* 25 4 12))
#+END_SRC

#+RESULTS:
: 75
: 1200

If you want to capture the results of both expressions, you could wrap them in a list,如果要捕获两个表达式的结果,可以将它们包装在一个列表中,

#+BEGIN_SRC elisp :results value verbatim
(list (+ 1 1) (* 2 2))
#+END_SRC

#+RESULTS:
: (2 4)

#+BEGIN_SRC python :session test :results value verbatim
1 + 1, 2 + 2
#+END_SRC

#+RESULTS:
: (2, 4)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM