Why compile Python code?

后端 未结 10 1853
时光取名叫无心
时光取名叫无心 2020-11-27 09:37

Why would you compile a Python script? You can run them directly from the .py file and it works fine, so is there a performance advantage or something?

I also notic

10条回答
  •  广开言路
    2020-11-27 10:05

    It's compiled to bytecode which can be used much, much, much faster.

    The reason some files aren't compiled is that the main script, which you invoke with python main.py is recompiled every time you run the script. All imported scripts will be compiled and stored on the disk.

    Important addition by Ben Blank:

    It's worth noting that while running a compiled script has a faster startup time (as it doesn't need to be compiled), it doesn't run any faster.

提交回复
热议问题