아래 글에 정말 잘 설명되어 있다! (Interpreted & compiled, Bytecode vs machine code, PyPy Just-In-Time compiler 등 설명)

https://www.toptal.com/python/why-are-there-so-many-pythons

 

Why Are There So Many Pythons? A Python Implementation Comparison

Starting from scratch, the author of this guide examines the various Python interfaces, implementations, and their characteristics.

www.toptal.com

The Python Interface_ Comparing Its Many Implementations _ Toptal.mhtml
3.23MB

 

 

Q. Python이면 Python이지, CPython, Jpython, PyPy같은건 또 뭐야?

😮 Python은 class interface와 같음.

Python이 어떻게 작동해야 하는지 rule은 정해져 있는데, 구체적인 implementation은 다른 프로그래머들에게 맡긴 것.

The first thing to realize when making a comparison is that ‘Python’ is an interface. There’s a specification of what Python should do and how it should behave (as with any interface). And there are multiple implementations (as with any interface).

 

그리고 implementation에 따라 interpreted 방식으로 작동할 수도 있고, compiled 방식으로 작동할 수도 있음.

The second thing to realize is that ‘interpreted’ and ‘compiled’ are properties of an implementation, not an interface.

 

아래 링크에서 여러 종류의 Python implementation을 찾아볼 수 있다

CPython is considered the default traditional implementation

https://wiki.python.org/moin/PythonImplementations

https://www.python.org/download/alternatives/

 


 

Q. Why are there so many implementations? Why are they needed?

“Why would you ever use an alternative implementation?”, you might ask. Well, for one, these different Python implementations play nicely with different technology stacks.

 

Python을 구현한 언어(C, C#, Java, ...)의 기능을 가져다 쓰거나, 내가 그 언어를 사용해서 모듈을 추가로 제작 가능

CPython makes it very easy to write C-extensions for your Python code because in the end it is executed by a C interpreter. Jython, on the other hand, makes it very easy to work with other Java programs: you can import any Java classes with no additional effort, summoning up and utilizing your Java classes from within your Jython programs.

 

예시)

  • Jython 코드에서 Java class를 가져다가 쓸 수 있음
# Java 처럼 보이지만, Jython 코드임
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_51
>>> from java.util import HashSet
>>> s = HashSet(5)
>>> s.add("Foo")
>>> s.add("Bar")
>>> s
[Foo, Bar]

위처럼 Python 코드 내에서 Java를 사용하거나, 반대로 Java 코드 내에 Jython code를 삽입하는 것도 가능 👏

https://www.jython.org/

 

 

 

 

기타 참고할만한 자료)

+ Recent posts