Hot answers tagged

3

Use C-u C-c C-c. See python-shell-buffer-substring function docstring: When optional argument NOMAIN is non-nil everything under an if __name__ == '__main__' block will be removed. And python-shell-send-buffer: When optional argument SEND-MAIN is non-nil, allow execution of code inside blocks delimited by if __name__== '__main__':. When called ...


1

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.


1

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.


Only top voted, non community-wiki answers of a minimum length are eligible