On Thu, 16 Jan 2014 23:43:02 -0500, Dave Angel wrote: > MRAB <pyt...@mrabarnett.plus.com> Wrote in message: >> On 2014-01-17 02:56, bob gailer wrote: >>> On 1/16/2014 8:01 PM, Sam wrote: >>>> One thing I observe about python byte-code compiling is that the main >>>> script does not gets compiled into .pyc. Only imported modules are >>>> compiled into .pyc. >>>> >>>> May I know how can I compile the main script into .pyc? >>> Duh? Just import it! >>> >> What if you want to just compile it? Importing will run it! >> >> >> > Importing will only run the portion of the code not protected by > > if __name__ == "__main__":
Nevertheless, there is no need to run *any* of the code just to compile it. [steve@ando ~]$ cat sample.py print("Hello!") [steve@ando ~]$ ls sample.pyc ls: sample.pyc: No such file or directory [steve@ando ~]$ python -m compileall sample.py Compiling sample.py ... [steve@ando ~]$ ls sample.p* sample.py sample.pyc [steve@ando ~]$ python sample.pyc Hello! -- Steven -- https://mail.python.org/mailman/listinfo/python-list