3 ms·
Python is an interpreted language with a compiler
- deleted 2y ago[deleted]
- zahlman 2y ago> When you run a Python program, it will run until it encounters an error, even if there's malformed syntax! As long as it doesn't need to load that malformed syntax, you're able to start running. Sure. However, Python "needs to load" the code an entire source file at a time. It will not ignore syntax errors elsewhere in the file; it will syntax-check the entire file before it executes anything, even though it executes top to bottom. This has historically been important during the 2-to-3 transition era; it's still common enough to find separate driver/entry-point .py files that are carefully made to use 2.x-compatible syntax, so that they can check `sys.version_info` and exit with a proper message rather than crashing with a `SyntaxError`. > But if you cargo run a Rust program, it won't run at all if it encounters an error in the compilation step! It has to run the entire compilation process before the program will start at all. This is only because "the entire compilation process" includes linking, which Python does not. Python's "entire compilation process" is a file at a time, since `import` is an entirely run-time construct. It's also entirely possible to use the Python standard library to precompile all the .py files in a project to .pyc, requesting the legacy naming/placement of those files (side by side with the source - as opposed to the new way of putting version-tagged bytecode into a `__pycache__` subdirectory), remove the corresponding .py files, and still run the program. That seems pretty meaningfully "compiled" to me (just, again, not "linked"). The drawback here is that stack traces won't show the original code, because the .pyc files don't store it (the default last-chance exception handler normally tries to look that up in the corresponding .py source).