How can I check the syntax of Python code in Emacs without actually executing it?

后端 未结 5 2045
醉话见心
醉话见心 2021-02-01 23:28

Python\'s IDLE has \'Check Module\' (Alt-X) to check the syntax which can be called without needing to run the code. Is there an equivalent way to do this in Emacs instead of ru

相关标签:
5条回答
  • 2021-02-01 23:36

    Or from emacs (or vim) you could run python -c 'import x' where x is the name of your file minus the .py extension.

    0 讨论(0)
  • 2021-02-01 23:40

    You can use Pyflakes together with Flymake in order to get instant notification when your python code is valid (and avoids a few common pitfalls as well).

    0 讨论(0)
  • 2021-02-01 23:42

    You can use pylint for such things and there seems to be a way to integrate it into emacs, but I've never done the latter b/c I'm a vim user.

    0 讨论(0)
  • 2021-02-01 23:47
    python -m py_compile script.py
    
    0 讨论(0)
  • 2021-02-01 23:52

    You can use pylint, pychecker, pyflakes etc. from Emacs' compile command (M-x compile).

    Hint: bind a key (say, F5) to recompile.

    0 讨论(0)
提交回复
热议问题