What is the difference between pyc and pyo files in Python?

I see that .pyc and .pyo files are compiled python code. What is the difference between them and when should I use one or the other?

+6
source share
2 answers

.pyc files are python files compiled into byte code by the interpreter. They are generated normally when the file is imported.

.pyo is compiled byte code without line numbers, statements, and some other things (possibly document lines) for optimization purposes.

when calling the python interpreter, you can pass the -O or -OO to create the .pyo file. Using -O throw out line numbers, statements, and some debugging information. -OO will cause the -OO file .pyo also have no docstrings.

+6
source

The difference between .pyo and .pyc is that .pyo optimized, which means you won’t be able to use certain functions like docstrings. .pyc is the whole deal without any restrictions.

0
source

Source: https://habr.com/ru/post/948731/


All Articles