.py to .pyc

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun May 13 20:03:54 EDT 2012


On Sun, 13 May 2012 23:36:02 +0200, Irmen de Jong wrote:

> On 13-5-2012 23:27, Colin J. Williams wrote:
>> Is there some way to ensure that a .pyc file is produced when executing
>> a .py file?
>> 
>> It seems that for small files the .pyc file is not produced.
>> 
>> Colin W.
> 
> All modules no matter how small produce a .pyc file *when they are
> imported*. If you start a module directly though, no .pyc is produced.
> (Notice that Python 3 puts the pyc files in a subdirectory.)

That's only the case for Python 3.2 and higher, not 3.1.

You can also use this:

python -m compileall

to produce .pyc files without waiting for them to be imported.



-- 
Steven



More information about the Python-list mailing list