4 ms·
There is no compile time in python
by the_clarence 2y ago
There is no compile time in python
- pansa2 2y agoYes there is, when it compiles source code to bytecode.
- zahlman 2y agoYes, there is. Python source code is translated into bytecode for a VM just like in Java or C#, and by default it's cached in .pyc files. It's only different in that you can ask to execute a source code file and the compilation happens automatically before the bytecode-interpretation. `SyntaxError` is fundamentally different from other exceptions because it can occur during compilation, and only occurs at run-time if explicitly raised (or via explicit invocation of another code compilation, such as with `exec`/`eval`, or importing a module). This is also why you can't catch a `SyntaxError` caused by the invalid syntax of your own code, but only from such an explicit `raise` or a request to compile a source code string (see https://stackoverflow.com/questions/1856408 https://stackoverflow.com/questions/1856408 ).