I do not prefer python-mode. I would like a generic way so that I can understand emacs.

I wish the file be saved and python file command then be run as if in a shell.

  • You can run a shell under emacs: M-x shell RET and execute commands in it.
    – NickD
    Jan 2 '20 at 17:30

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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.