Chapter 11: Pckages: Putting Classes Together

example 11.1, page no. 198

In [14]:
"""
Note there are no packages in Python, a python program(file) can be used as a module in anoter Python program
"""

from package1 import *
from package2 import *

a = classA()
b = classB()

a.display()
b.displayB()
Class A
Class B
m =  10.0

example 11.2, page no. 200

In [15]:
"""
Note there are no packages in Python, a python program(file) can be used as a module in anoter Python program
"""

from package2 import *

class classC(classB):
    n = 20
    def displayC(self):
        print "Class C"
        print "m = ", self.m
        print "n = ", self.n

c = classC()
c.displayB()
c.displayC()
Class B
m =  10.0
Class C
m =  10.0
n =  20

example 11.3, page no. 204

In [16]:
"""
there is no concept of static import. We will use normal import instead
"""

import math

class mathop:
    def circle(self, r):
        area = math.pi*r*r
        print "The Area of circle is: ", area

obj = mathop()
obj.circle(2.3)
The Area of circle is:  16.6190251375