Precimpiling *.py to *.pyc.

glefkowitz at origin.ea.com glefkowitz at origin.ea.com
Wed Sep 27 17:39:24 EDT 2000


David Porter <jcm at bigskytel.com> writes:

> * Thaddeus L. Olczyk <olczyk at interaccess.com>:
> > Is there any way of compiling all the *.py to *.pyc files?
> 
> Since they are compiled when imported as libraries, it would be easy to have
> a script import one after the other. E.G.,
> 
> import os
> for x in os.listdir('.'):
>     if x[-3:] == '.py':
>         exec('import '+x[0:-3])
> 	exec('del '+x[0:-3])
> 	
> 
> I don't know whether the last line is important or not.
> 
>   David
>   
>   
You might want to look into the 'compileall' module.



More information about the Python-list mailing list