Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Python spot errors before execution?

Tags:

python

Suppose I have the following code in Python:

a = "WelcomeToTheMachine"
if a == "DarkSideOfTheMoon":
    awersdfvsdvdcvd
print "done!"

Why doesn't this error? How does it even compile? In Java or C#, this would get spotted during compilation.

like image 409
Athena Avatar asked Jun 10 '16 19:06

Athena


1 Answers

Python isn't a compiled language, that's why your code doesn't throw compilation errors.

Python is a byte code interpreted language. Technically the source code gets "compiled" to byte code, but then the byte code is just in time (JIT) compiled if using PyPy or Pyston otherwise it's line by line interpreted.

The workflow is as follows :

Your Python Code -> Compiler -> .pyc file -> Interpreter -> Your Output

Using the standard python runtime What does all this mean? Essentially all the heavy work happens during runtime, unlike with C or C++ where the source code in it's entirety is analyzed and translated to binary at compile time.

like image 61
Jonathan Eustace Avatar answered Sep 30 '22 21:09

Jonathan Eustace