如果我在运行时修改Python脚本,将会发生什么?

问题:如果我在运行时修改Python脚本,将会发生什么?

想象一下,一个需要花费很长时间才能运行的python脚本,如果我在运行时对其进行修改,会发生什么?结果会有所不同吗?

Imagine a python script that will take a long time to run, what will happen if I modify it while it’s running? Will the result be different?


回答 0

没什么,因为Python将您的脚本预编译为PYC文件并启动它。

但是,如果发生某种异常,您可能会得到一个有点误导的解释,因为第X行的代码可能与启动脚本之前的代码不同。

Nothing, because Python precompiles your script into a PYC file and launches that.

However, if some kind of exception occurs, you may get a slightly misleading explanation, because line X may have different code than before you started the script.