compile shebang into pyc file

Jp Calderone exarkun at divmod.com
Wed Apr 27 11:53:54 EDT 2005


On Wed, 27 Apr 2005 10:37:11 -0400, Michael Soulier <msoulier at gmail.com> wrote:
>On 26 Apr 2005 18:15:51 -0700, johnlichtenstein at gmail.com
><johnlichtenstein at gmail.com> wrote:
>> Is there some reason why you want to run the .pyc file, rather than the
>> .py file? If you start the script with
>
>a. It's more efficient, since the code doesn't need to be compiled
>before it's run.
>b. What if you want to ship closed-source?
>

  I don't think either of these reasons is particularly compelling.  

    To avoid the costs of byte compilation (which are typically pretty minimal), structure your code to have a simple, short main .py file which imports most of its code from other modules.  This gives you the automatic byte compilation caching behavior Python normally uses for imports for the bulk of your code.

    Shipping closed source takes a lot more than just shipping .pyc files.  .pyc files are trivially (or near trivially) converted back into .py files.  The only parts which cannot be restored are the comments, which are discarded at compilation time.

  Jp



More information about the Python-list mailing list