When you run a .py
file, it is first compiled to bytecode, then executed. The loading of such a file is slower because for a .pyc
, the compilation step has already been performed, but after loading, the same bytecode interpretation is done.
In pseudocode, the Python interpreter executes the following algorithm:
code = load(path)
if path.endswith(".py"):
code = compile(code)
run(code)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…