But, 1 + 1 should be 11. Joke aside, for Python, how you return the value depend of if you use a session or not.
By default, a Python code block do not use a session. In this case, when
executed, the code is wrapped into a Python function and then this
function is called. So, to return a value, you need to use the "return"
statement.
With your example:
src_python{return 1 + 1}
When you use a session for your code block, the last statement value is
returned if it is a top level expression. In this case, you do not use a
"return" statement.
Is it the article you have read on WORG ?
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html
The part you have quoted maybe miss a reference to the section who
explain how the return mechanism work for values.
Best regards
-------
Gendre Sébastien
Rudolf Adamkovič <[email protected]> writes:
> Today, I decided to start using Python in Org.
>
> (1) I read in "WORG":
>
> :results {output, value}: [...] Value results are the value of the
> last expression evaluated in the code block. Value mode is the default
> (as with other languages).
>
> (2) So, I try it, and get:
>
> src_python{1 + 1} {{{results(=None=)}}}
>
> I expected this to be 2.
>
> Questions:
>
> - Who is correct: (1) the documentation or (2) the implementation?
> - If (2) is correct, do I have to write `return' every time?
>
> Rudy
signature.asc
Description: PGP signature
