Compiled Python files
Whenever module1.py
and module2.py
are successfully compiled, an attempt is made to write the compiled version to module1.pyc
and module2.pyc
respectively. Refer to the following screenshot:
A screenshot showing the compiled files
The contents of the compiled file is platform independent, so a Python module can be used by machines on different architectures.
Let's discuss a special scenario, consider Bob make a program named myprog.py
as shown:
def sum1(a,b): c = a+b return c print "Sum is ", sum1(3,6)
Let's run it:
Output of the myprog.py program
Bob's program is running successfully. Consider another user, Alice, who uses your program as a module.
Refer to Alice's program alice1.py
:
import myprog num = 10 total = num+myprog.sum1(23,12) print "Alice total is ", total
The preceding program is very simple, just import myprog.py
as a module and use the sum1()
function of the myprog
module. Let's see the output:
Output of the alice1.py program
The program is running successfully...