[Tutor] py_compile and chmod +x

Andreas Kostyrka andreas at kostyrka.org
Fri Dec 19 18:21:06 CET 2008


Am Fri, 19 Dec 2008 09:01:24 -0500
schrieb "Emad Nawfal (عماد نوفل)" <emadnawfal at gmail.com>:

You are not supposed to compile the main script.

pyc files are automatically generated when you import the py file (but
not execute it), if you are allowed to write them beside the py file.

When a pyc file exists, and it's newer than the py file, python will
import the py file from the pyc file, thus saving on parsing the py
file.

In effect the pyc file is nothing more than a file cache for the parsed
and bytecompiled version of the py file.

Andreas

> Hi Tutors,
> #! /usr/bin/env python
> print "Hello Tutors"
> 
> I have this script saved as hello.py. Why can  I execute it, but not
> the compiled version?  or am I doing something wrong? Just curious.
> Any help appreciated.
> For example :
> 
> 
> emad at emad-laptop:~/Desktop/Programming/Haskell$ chmod  +x  hello.py
> emad at emad-laptop:~/Desktop/Programming/Haskell$ ./hello.py
> Hello Tutors
> 
> Now I compile it in Python:
> >>> import py_compile
> >>> py_compile.compile("hello.py")
> >>>
> emad at emad-laptop:~/Desktop/Programming/Haskell$ chmod +x hello.pyc
> 
> emad at emad-laptop:~/Desktop/Programming/Haskell$ ./hello.pyc
> : command not found: �
> ./hello.pyc: line 2: syntax error near unexpected token `('
> ./hello.pyc: line 2: `�KIc@s    dGHdS(s
>                                          Hello
> TutorsN((((hello.py<module>s'
> emad at emad-laptop:~/Desktop/Programming/Haskell$
> 
> 


More information about the Tutor mailing list