Why is python treated as a interpreted language when it has a compiling stage? [closed]

Why is that python is treated as only an interpreted language when there is in fact a compiling stage where the code we write gets converted into byte code(.pyc), which is later interpreted by the PVM. Is it wrong to say python is just an interpreted language?

3

Is Python interpreted (like Javascript or PHP)? is worth a read for more information and it says:

…different implementations of languages may do different things. These days you can find both C interpreters and Javascript compilers.

Compiled and interpreted are descriptions of an implementation, not of a language; Their usage in relation to languages is a throwback to the days when each language had few implementations and similar (simple) toolchains compared to the kinds of functions you might find in an IDE today.

There are layers of interpretation/compilation…

  • Pure interpretation
  • Tokenisation + interpretation
  • Bytecode compilation which requires a virtual machine to host
  • Bytecode + ‘just in time’ compilation to Machine code
  • Native Machine code compilation

Different Python environments use different options, cpython does only a bytecode compilation, where Psyco uses a bytecode + JIT approach.

New languages and implementations frequently use the Bytecode + JIT approach as it is the best way to make them portable and enables the application to make use of more features of an unknown host environment.

In terms of the language itself the descriptions are used as a shorthand for the level of abstraction. With high-level languages like Python where performance consideration and optimisation is far removed from the programmers remit often described as being interpreted, where low level ones like C where those considerations are closely tied are considered compiled.

To answer to your question – Python as most people use it is PARTIALLY COMPILED and it would be right to consider it BOTH compiled AND interpreted.

3

This is a bit of a simplification, but there are three main steps in compiling code:

  1. Parse the source code to a syntax tree
  2. Compile the syntax tree into machine-independent byte code
  3. Translate byte code to machine code

A C compiler does all three, and is without doubt a compiler. A Java compiler does 1 and 2, producing .class files, and the runtime does 3. The Python “compiler” only does step 1 when producing .pyc files, while the runtime does 2 and 3.

So, as Bart says, the difference between “compiled” and “interpreted” is somewhat subjective. But step 2 is a very significant step, and it is the most difficult to do in reverse, i.e. decompile. So that’s why Java is usually called compiled and Python usually called interpreted.


The above is my original post. Since posting I’ve read more about .pyc files and need to correct it. The Python compiler does actually do step 2; the contents of pyc files is a stack-based intermediate language, quite similar to Java class files.

I wonder if the reason that Python is considered “interpreted” is because there’s a single binary to compile and execute.

3

Unlike .NET and Java, there is not a well-defined standard for python byte code, and they sometimes change it from version to version. See also this question.

This has the implication that you can’t really distribute the compiled version of your code, which in turn means, that you can’t really consider it a compiled language.

1

With python, you can enter a line of code into python and expect it to be interpreted and executed immediately.

Compiled languages like c, java, etc. require a compilation step which render an object that may be executable. There may be additional steps require to make the code executable.

Unlike an compiled language, an interpreted language can run a command like:

print "Hello"

1

There is no clear distinction anymore between compiled and interpreted languages any more, as there are very few languages left that are purely interpreted.

It seems like that the term ‘interpreted language’ is actually being used for scripting languages, where you can work in a tight “modify – execute” cycle without an explicit compilation step in the workflow.

You can say that when we’re talking about Python as a whole; including compiler that creates byte code and a virtual machine that interprets the byte code. Python as an language has no saying about if it’s an compiled or interpreted programming language, only the implementation of it. Often with semantic issues, there are programming languages where the user can choose to compile the code into byte code to be interpreted at run time or compile it directly into machine code.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật