[ACCEPTED]-Is Python interpreted (like Javascript or PHP)?-python
As the varied responses will tell you, the 52 line between interpreted and compiled is 51 no longer as clear as it was when such terms 50 were coined. In fact, it's also something 49 of a mistake to consider languages as being either 48 interpreted or compiled, as different implementations of 47 languages may do different things. These 46 days you can find both C interpreters and Javascript compilers.
Even when looking 45 at an implementation, things still aren't 44 clear-cut. There are layers of interpretation. Here 43 are a few of the gradations between interpreted 42 and compiled:
Pure interpretation. Pretty 41 much what it says on the tin. Read a line 40 of source and immediately do what it says. This 39 isn't actually done by many production languages 38 - pretty much just things like shell scripts.
Tokenisation + interpretation. A 37 trivial optimisation on the above. Rather 36 than interpret each line from scratch, it's 35 first tokenised (that is, rather than seeing 34 a string like "print 52 + x", it's 33 translated into a stream of tokens (eg.
[PRINT_STATEMENT, INTEGER(52), PLUS_SIGN, IDENTIFIER('x')]
) to 32 avoid repeatedly performing that state of 31 interpretation. Many versions of basic 30 worked this way.Bytecode compilation. This is the 29 approach taken by languages like Java and 28 C# (though see below). The code is transformed 27 into instructions for a "virtual machine". These 26 instructions are then interpreted. This 25 is also the approach taken by python (or 24 at least cpython, the most common implementation.) The 23 Jython and Ironpython implementations also take this approach, but 22 compile to the bytecode for the Java and 21 C# virtual machines resepectively.
Bytecode 20 + Just in Time compilation. As above, but rather than interpreting 19 the bytecodes, the code that would be performed 18 is compiled from the bytecode at the point 17 of execution, and then run. In some cases, this 16 can actually outperform native compilation, as 15 it is free to perform runtime analysis on 14 the code, and can use specific features 13 of the current processor (while static compilation 12 may need to compile for a lowest common 11 denominator CPU). Later versions of Java, and 10 C# use this approach. Psyco performs this for 9 python.
Native machine-code compilation. The 8 code is compiled to the machine code of 7 the target system. You may think we've 6 now completely eliminated interpretation, but 5 even here there are subtleties. Some machine 4 code instructions are not actually directly 3 implemented in hardware, but are in fact 2 implemented via microcode - even machine code is 1 sometimes interpreted!
There's multiple questions here:
- No, Python is not interpreted. The standard implementation compiles to bytecode, and then executes in a virtual machine. Many modern JavaScript engines also do this.
- Regardless of implementation (interpreter, VM, machine code), anything you want can run in the background. You can run shell scripts in the background, if you want.
0
Technically, Python is compiled to bytecode 17 and then interpreted in a virtual machine. If the Python 16 compiler is able to write out the bytecode 15 into a .pyc file, it will (usually) do so.
On 14 the other hand, there's no explicit compilation 13 step in Python as there is with Java or 12 C. From the point of view of the developer, it 11 looks like Python is just interpreting the 10 .py file directly. Plus, Python offers an 9 interactive prompt where you can type Python 8 statements and have them executed immediately. So 7 the workflow in Python is much more similar 6 to that of an interpreted language than 5 that of a compiled language. To me (and 4 a lot of other developers, I suppose), that 3 distinction of workflow is more important 2 than whether there's an intermediate bytecode 1 step or not.
Python is an interpreted language but it 5 is the bytecode which is interpreted at 4 run time. There are also many tools out 3 there that can assist you in making your 2 programs run as a windows service / UNIX 1 daemon.
Yes, Python is interpreted, but you can 1 also run them as long-running applications.
Yes, it's interpreted, its main implementation 5 compiles bytecode first and then runs it 4 though (kind of if you took a java source 3 and the JVM compiled it before running it). Still, you 2 can run your application in background. Actually, you 1 can run pretty much anything in background.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.