How do you run Python code using Emacs?

后端 未结 4 1827
迷失自我
迷失自我 2020-12-12 15:59

I\'m trying to run Python code for testing and debugging using Emacs. How should I debug and run code in *.py files ? I tried using the M-x compile commands . U

4条回答
  •  悲哀的现实
    2020-12-12 16:36

    Once you open your python file in Emacs, you will need to start the python process with: M-x run-python or C-c C-p, which creates an inferior python shell buffer. This buffer will be created by a horizontal split, and the active buffer will be the one containing the python file.

    Then you can do C-c C-c, which will send the current python buffer to the inferior python shell below. This is where you will see the output of your python file.

    To switch to and from your python file buffer and the inferior python shell buffer, you can do C-x o.

    If you accidentally close one of the buffers, you can switch between buffers with C-x C- and C-x C- and perform operations on the python buffer like the ones mentioned by Aaron Hall.

    NOTE:

    1. Running GNU Emacs 26.2 without any extensions.

    2. Did not define if (__name__ == '__main__'): block

提交回复
热议问题