[Tutor] py_compile and chmod +x

Emad Nawfal (عماد نوفل) emadnawfal at gmail.com
Fri Dec 19 18:36:08 CET 2008


Thank you so much. This has been very helpful.

On Fri, Dec 19, 2008 at 12:21 PM, Andreas Kostyrka <andreas at kostyrka.org>wrote:

> 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    dGHd S( s
> >                                          Hello
> > TutorsN((((hello.py<module> s'
> > emad at emad-laptop:~/Desktop/Programming/Haskell$
> >
> >
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081219/1918a0c6/attachment-0001.htm>


More information about the Tutor mailing list