Use find-directory-in-project-by-selected from https://github.com/technomancy/find-file-in-project
I also wrote a prototype in pure Lisp. It does not use any third party command line program or package,
(defun my-open-dir-in-project ()
"Open directory in project."
(let* ((root (...
You could use M-x compile with an appropriate compile-command value. e.g. as a file-local variable:
# -*- compile-command: "python file.py"; -*-
Emacs will prompt you to save (or not) the file before running the command.
Use M-! (M-x shell-command) if you want to run a shell command,
e.g. python file.py and print the output in a new buffer (*Shell
Command Output*). That does not open a shell in a new buffer.
Use M-x shell to run a shell in a new buffer as pointed by @NickD.
You need to distinguish between
interactive command. The latter is also a function, but with the addition of (interactive) to its body.
You can run the latter, but not the former, by binding commands to
keys or calling them by name via M-x. See the elisp manual
links above more more details.