본문 바로가기

Python

.pyc란 무엇인가?

파이썬은 인터프리터 언어라고 알려져있다.

파이썬을 실행하면 나오는 .pyc는 무엇일까?

python 언어를 컴파일해 놓은 파일인데 이 안에는 원시 파이썬 코드가 컴파일된 byte 코드가 존재한다.

인터프리터 언어인데 byte 코드로 컴파일을 했다니 좀 이상하다.

 

파이썬 가상 머신(virtual machine)은 컴파일러와 인터프리터가 있다.

인터프리터는 .py 파일에 작성된 원시 파이썬 코드를 곧바로 해석할 수 없다.

그렇기 때문에 우선 원시 코드는 byte 코드로 변환되어야 한다. 이 과정에서 .pyc 파일이 생성되고 그 안에 byte 코드가 작성된다.

.pyc 파일이 이미 생성되어 있으면 다시 컴파일할 필요 없이 바로 시스템에 byte 코드를 적재한다.

.pyc 파일은 캐시처럼 취급된다. 미리 byte 코드를 만들어 놓고 인터프리터로 코드를 실행하기 때문에 속도가 향상된다.

 

결국 순수한 인터프리터 언어도 아니고 순수한 컴파일 언어도 아닌 것이다.

 

파이썬 원시 코드 in .py -> byte 코드 in .pyc -> 실행
  컴파일러   인터프리터  

 

출처

https://stackoverflow.com/questions/2998215/if-python-is-interpreted-what-are-pyc-files

 

If Python is interpreted, what are .pyc files?

I've been given to understand that Python is an interpreted language... However, when I look at my Python source code I see .pyc files, which Windows identifies as "Compiled Python Files". Where do...

stackoverflow.com

http://www.techdarting.com/2014/04/python-compiled-or-interpreted-language.html

 

Python is compiled language or interpreted language ?

Python, Python compiler vs interpreter, python compiler, python interpreter, compiler vs interpreter, python compiled or interpreted, python compiled or interpreted language, Python interpreter vs python compiler, python is interpreted language.

www.techdarting.com

http://net-informations.com/python/iq/interpreted.htm

 

Is Python interpreted, or compiled, or both?

 

net-informations.com