Re: [Orgmode] What is output for org-babel?
Dan Davison davi...@stats.ox.ac.uk writes: Darlan Cavalcante Moreira darc...@gmail.com writes: ... So I investigate and for example this #+BEGIN_SRC python import os; os.listdir(os.getcwd()) #+END_SRC This does not return anything for me either, but #+BEGIN_SRC python import os os.listdir(os.getcwd()) #+END_SRC works as expected. This is strange, since import os; os.listdir(os.getcwd()) is valid and will work if typed in the python interpreter directly. This is a limitation of the current implementation of :results value evaluation. I've just pushed a change which fixes this and related problems. It introduces a change for python users: when using the default evaluation mode (':results value' non-session), if you want the source code block to return a value, you must now include the 'return' statement that would be required if you were writing a python function definition. On Worg I've added some more detailed documentation of exactly how the result is obtained in the four different cases (value/output, session/non-session), and I'm also pasting that below. Dan *** Evaluation results: output/value session/non-session The following applies particularly to perl, python, R and ruby. Nature of Results: || non-session | session | |+--+-| | value | value of last expression | value of last expression| | output | contents of stdout | concatenation of interpreter output | Note that in ':results value' (session and non-session), the result is imported into org-mode as a table (a one- or two-dimensional vector of strings or numbers) when appropriate. :results value (non-session) This is the default. Internally, the value is obtained by wrapping the code in a function definition in the external language, and evaluating that function. Therefore, code should be written as if it were the body of such a function. In particular, note that python does not automatically return a value from a function unless a =return= statement is present, and so a 'return' statement will usually be required in python :results value (non-session). This is the only one of the four evaluation contexts in which the code is automatically wrapped in a function definition. :results output (non-session) The code is passed to the interpreter as an external process, and the contents of the standard output stream is returned as text. (In certain languages this also contains the error output stream; this is an area for future work.) :results value (session) The code is passed to the interpreter running as an interactive emacs inferior process. The result returned is the result of the last evaluation performed by the interpreter. (This is obtained in a language-specific manner: the value of the variable =_= in python and ruby, and the value of =.Last.value= in R). :results output (session) The code is passed to the interpreter running as an interactive emacs inferior process. The result returned is the concatenation of the sequence of (text) output from the interactive interpreter. Notice that this is not necessarily the same as what would be sent to stdout if the same code were passed to a non-interactive interpreter running as an external process. For example, compare the following two blocks: #+begin_src python :results output print hello 2 print bye #+end_src #+resname: : hello : bye In non-session mode, the '2' is not printed and does not appear. #+begin_src python :results output :session print hello 2 print bye #+end_src #+resname: : hello : 2 : bye But in session mode, the interactive interpreter receives input '2' and prints out its value, '2'. (Indeed, the other print statements are unnecessary here). ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] What is output for org-babel?
andrea Crotti wrote: I'm with org-mode 6.31a, I was trying to get output in the exported files but I never see the output. Hi, not sure if this is related -- or helpful, but here goes! When I export the following file: start--- * lowercase #+begin_src python :exports results 2+2 #+end_src * uppercase #+BEGIN_SRC python :exports results 2+2 #+end_src end--- the results are (copied from pdf): start--- 1 lowercase 4 2 uppercase 2+2 end--- Writing begin_src in lowercase or uppercase makes a difference. I am not sure if this is a feature or a bug. Martin ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] What is output for org-babel?
Martin G. Skjæveland wrote: andrea Crotti wrote: I'm with org-mode 6.31a, I was trying to get output in the exported files but I never see the output. Writing begin_src in lowercase or uppercase makes a difference. I am not sure if this is a feature or a bug. Oh, forgot to mention: I can't make any of the snippets you sent work. Everything in the source blocks is exported as verbatim text, regardless of upper/lowercase, or :results output or not. Martin ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] What is output for org-babel?
Martin G. Skjæveland mart...@ifi.uio.no writes: andrea Crotti wrote: I'm with org-mode 6.31a, I was trying to get output in the exported files but I never see the output. Hi, not sure if this is related -- or helpful, but here goes! When I export the following file: start--- * lowercase #+begin_src python :exports results 2+2 #+end_src * uppercase #+BEGIN_SRC python :exports results 2+2 #+end_src end--- the results are (copied from pdf): start--- 1 lowercase 4 2 uppercase 2+2 end--- Writing begin_src in lowercase or uppercase makes a difference. I am not sure if this is a feature or a bug. Bug. However I'm not sure whether it is in org-mode or org-babel. In general in org-mode, begin_src and BEGIN_SRC are equivalent (true for all #+XXX directives I think). However, in this case the org-exp-blocks client (org-babel) associates 'src' with its own block exporter, but it says nothing about 'SRC'. So the solution could either be: (a) Bug in the org-exp-blocks client (org-babel). The client should explicitly hook up 'SRC' to its block pre-processor. (b) Bug in org-mode. Org-exp-blocks should call the block pre-processor for 'src' when it finds 'SRC' (and equivalently, if a client registers 'SRC', then 'src' should trigger it.) I'm leaning towards (b), seeing as we already have the case insensitivity in org-mode. Dan Martin ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] What is output for org-babel?
Darlan Cavalcante Moreira darc...@gmail.com writes: COmments are inline. At Thu, 5 Nov 2009 11:17:39 + (UTC), andrea Crotti andrea.crott...@gmail.com wrote: I'm with org-mode 6.31a, I was trying to get output in the exported files but I never see the output. So I investigate and for example this #+BEGIN_SRC python import os; os.listdir(os.getcwd()) #+END_SRC This does not return anything for me either, but #+BEGIN_SRC python import os os.listdir(os.getcwd()) #+END_SRC works as expected. This is strange, since import os; os.listdir(os.getcwd()) is valid and will work if typed in the python interpreter directly. This is a limitation of the current implementation of :results value evaluation. For now, while we work out a good solution, semi-colon separated statements on the same line (as well as multiline continuations) should be avoided when using :results value (the default). It does work with :results output: #+BEGIN_SRC python :results output import os; print os.listdir(os.getcwd()) #+END_SRC Thanks for pointing this problem out. Dan ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode