Search code examples
pythontestingemacspython-mode

using emacs-mode.el to execute with arguments


I'm writing a script that takes arguments, and I'd like to use emacs-model.el's C-c C-c to execute it while I'm writing it. But this merely runs the script without arguments, which then causes my script to complain.

Is there an elegant way around this? My current solution is to hardcode the arguments.


Solution

  • C-c C-c isn't the right command to run your Python script. It will send your current buffer to the Python interpreter, just as though you had entered it there manually. If you used the recommended if __name__ == '__main__': line in your script, it won't run there anyway.

    A better way is the command "shell-command", bound to M-!. You can enter the shell command to run your script in the minibuffer, and recall it the next time with M-p. See more details with C-h k M-!.