0

so far we know that we can pre-compile the python scripts using

python -m py_compile script.py

but my question is what are the advantages of doing so ?? I knew that it will not compile in case of indentation error and synatx error in python code. A part from this what all other error it will check for

Like will it check for any type error??

Example could be addition of a `int` and `string`    x= 10+hello

or any wrong function calls

 range(2,4,6,7)  - wrong call as it contains 4 parameters

Please clarify with a better explanation .

coder3521
  • 2,608
  • 1
  • 28
  • 50

1 Answers1

0

Your two examples (TypeError, and incorrect range()call (also a TypeError btw)) are not Syntax errors, so will not get caught at compile-time.

They will produce Exceptions which can only get caught when the code is executed.

As far as what the advantages are, from the docs:

This function can be useful when installing modules for shared use, especially if some of the users may not have permission to write the byte-code cache files in the directory containing the source code.

Also, from this question:

...the only thing that's faster about ‘.pyc’ or ‘.pyo’ files is the speed with which they are loaded.

Which is an advantage if your code is large, although Python keeps the compiled files anyway, so manually compiling them isn't going to gain you much.

Community
  • 1
  • 1
SiHa
  • 7,830
  • 13
  • 34
  • 43