Reg Python Byte code

Magnus Lycka lycka at carmen.se
Mon Aug 22 07:46:44 EDT 2005


praba kar wrote:
>       Python 2.3 creates byte code with *.pyc
> extention.  But Python 2.4 creates bytes code with
> *.pyo.  Is there any difference between *.pyc
> and *.pyo?.

Since way back, ordinary Python bytecode uses .pyc,
and optimized Python bytecode (python -O) uses .pyc.
This has nothing to do with Python versions. As I
recall, Python installers on the most common platforms
have pre-generated both .pyc and .pyo file for the
standard library since before 2.3.

>      Actually After python compiled a program
> then that program will run from the *.pyc byte
> code.  If I delete that byte code what will be
> happen.? 

Python will have to compile the module again, the
next time it's imported.

>      If I delete *.pyc byte code in the python
> 2.3 then It will create  again *.pyc byte code.
> But If I delete *.pyo byte code in the python
> 2.4 then It will not create again *.pyo. Why
> this difference.

Because you didn't use 'python -O'. It used the
.pyc version, not the .pyo. It's there too!

>      If I delete byte code of the python.
> I want to know Whether it will affect the
> performance of the programme or not.

There is little point in removing files that
will come back again. If you're allergic to
bytecode files, you can writeprotect those
dictionaries though. Each python process that
imports a module will then have to compile the
module. Whether this affects performance depends
on how you use Python. For long runinng tasks,
it will probably not matter, for e.g. big CGI
scripts, it might have severe implications.



More information about the Python-list mailing list