emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sébastien Gendre" <seb@k-7.ch>
To: "Rudolf Adamkovič" <rudolf@adamkovic.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: Org Babel says 1 + 1 in Python is None
Date: Sat, 07 Sep 2024 11:27:39 +0200	[thread overview]
Message-ID: <87wmjnbypg.fsf@k-7.ch> (raw)
In-Reply-To: <m27cboucsz.fsf@adamkovic.org> ("Rudolf Adamkovič"'s message of "Fri, 06 Sep 2024 15:33:32 +0200")

[-- Attachment #1: Type: text/plain, Size: 1457 bytes --]


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č <rudolf@adamkovic.org> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 849 bytes --]

  parent reply	other threads:[~2024-09-07  9:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06 13:33 Org Babel says 1 + 1 in Python is None Rudolf Adamkovič
2024-09-07  8:12 ` Dr. Arne Babenhauserheide
2024-10-13 11:41   ` Ihor Radchenko
2024-10-20  7:08     ` Jack Kamm
2024-10-20  9:39       ` Ihor Radchenko
2024-10-21  6:00         ` Jack Kamm
2024-10-21 18:03           ` Ihor Radchenko
2024-10-22  2:43             ` Jack Kamm
2024-10-23 17:13               ` Ihor Radchenko
2024-09-07  9:27 ` Sébastien Gendre [this message]
2024-10-28 22:25   ` Rudolf Adamkovič

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wmjnbypg.fsf@k-7.ch \
    --to=seb@k-7.ch \
    --cc=emacs-orgmode@gnu.org \
    --cc=rudolf@adamkovic.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).