.py vs .pyc

S

Sakcee

Hi all

is execution of pyc files faster than py files? since both files are
interpreted by python , is there any speedup in using one or other?

what is difference if i type from cmd line,
python test.py vs. python test.pyc


thanks
 
D

Duncan Booth

Sakcee said:
is execution of pyc files faster than py files? since both files are
interpreted by python , is there any speedup in using one or other?

what is difference if i type from cmd line,
python test.py vs. python test.pyc
There was no need to post your question twice.

Python compiles .py files and (if it can) saves the compiled code in a .pyc
file. Next time around it can simply load the .pyc file and bypass the
compilation stage. There is no difference in execution speed, in both cases
the same compiled code will be executed.

The main script (the one named on the command line) works slightly
differently from imported modules in that a .pyc file is not automatically
generated or used, so the compilation happens every time.
Unless you have a very large script the difference in load time is not
likely to be noticeable (and if you have a very large script then you
should split it into modules).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,369
Latest member
Carmen32T6

Latest Threads

Top