Python- Modules

#To organize code
#can define class, function, Variables
#import module_name
#from module_name import Class_name
#Example Module

A.py
#!/usr/bin/python
#A

def quickAdd(a,b):
    print'From A quickAdd()'
    return a+b

B.py
#!/usr/bin/python
#B
def quickAdd(a,b):
        print 'From B quickAdd()'
        return a+b



test.py
#!/usr/bin/python
import A
import B
print'%d'%A.quickAdd(5,2)
print'%d'%B.quickAdd(5,2)

#test.py another way to classes class
#here classEx.py is file having Calculator class

#!/usr/bin/python
from classEx import Calculator

im=Calculator(10,5)
print'%d'%im.add()
print'%d'%im.mul()

Reactions: