From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Jack Kamm <jackkamm@gmail.com>
Cc: Bastien <bzg@gnu.org>, org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] (Tiny) Tweak Python session null return value
Date: Mon, 17 Feb 2020 14:45:23 -0500 [thread overview]
Message-ID: <CAJ51ETrF4d=8NKd13Zh9=Q3N_YkRoM7h-hkuB_63kMO5Nrtdmg@mail.gmail.com> (raw)
In-Reply-To: <877e0lf307.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2507 bytes --]
I can see why you would want to see True/False there, but to get the value,
you need to specifically return what you want because AFAIK the body is
wrapped in a function that is evaluated to get the value, it is not simply
the last thing that gets evaluated. Your example clarified to me at least
why it would be tricky to figure it out, you can't rely on the last line,
for example. I don't know if there is some special Python variable that
contains that.
It is also a little strange to me to put return specifically in like this:
#+begin_src python :session :results value
if some_condition:
a = True
else:
a = False
return a
#+end_src
or:
#+BEGIN_SRC python :results value
a = 1
return True if a else False
#+END_SRC
#+RESULTS:
: True
because it is not valid syntax in a script (try it with :results output),
but this is how it has been for ob-python all along when what you want is
the value returned.
John
-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Mon, Feb 17, 2020 at 2:06 PM Jack Kamm <jackkamm@gmail.com> wrote:
> Hi John,
>
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
> > I think None is correct. If you don't specify a return value in Python,
> > then a function returns None. I would expect that to happen in a Python
> > block too.
>
> Hmm, OK, thanks for your intuition, it's useful feedback.
>
> Working this out loud, I was considering the following sort of block:
>
> #+begin_src python :session :results value
> if some_condition:
> True
> else:
> False
> #+end_src
>
> #+RESULTS:
> : None
>
> Ideally, it would return True/False, but the current implementation
> cannot grab that result unfortunately. (In its defense, it at least
> doesn't crash like it did before).
>
> I was thinking not printing anything at all under "#+RESULTS" would be
> less surprising than printing "None". But both are admittedly surprising
> at first.
>
> I agree your preference of returning "None" is the more technically
> consistent behavior though.
>
> I don't want to rush a decision now, I think I need to gather more user
> feedback after the 9.4 release. I'll ask Bastien to revert that commit
> and put this off to 9.5, rather than writing an updated NEWS entry like
> he asked.
>
> Either way, we'll need to update Worg to clearly document what's going
> on here.
>
[-- Attachment #2: Type: text/html, Size: 3531 bytes --]
next prev parent reply other threads:[~2020-02-17 19:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-17 16:24 [PATCH] (Tiny) Tweak Python session null return value Jack Kamm
2020-02-17 17:42 ` Bastien
2020-02-17 19:07 ` Jack Kamm
2020-02-17 22:53 ` Bastien
2020-02-17 17:52 ` John Kitchin
2020-02-17 19:05 ` Jack Kamm
2020-02-17 19:45 ` John Kitchin [this message]
2020-02-17 20:45 ` Jack Kamm
2020-02-17 22:27 ` John Kitchin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJ51ETrF4d=8NKd13Zh9=Q3N_YkRoM7h-hkuB_63kMO5Nrtdmg@mail.gmail.com' \
--to=jkitchin@andrew.cmu.edu \
--cc=bzg@gnu.org \
--cc=emacs-orgmode@gnu.org \
--cc=jackkamm@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.