I’ve found a few partial solutions:
1)
#+begin_src emacs-lisp :results raw :exports (if (eq org-export-current-backend
'beamer) "results" "none")
(eval (concat "#+begin_src python\n print('Hello, world')\n#+end_src"))
#+end_src
This prints the python code if exporting to Beamer and not if
I’ve been experimenting with using a single org file to generate an article
when exported to LaTeX (or HTML) and a Beamer presentation when exported to
Beamer, without requiring any edits to the org file itself.
For this to be really useful, the exporter has to be able to do different
things