module : module that means nothing, that means simple dot py file that's it

NOTE:Any python file referenced as a modules

package : package that means nothing, that means simple folders

In Python two types of modules

  • per-defined modules
  • user defined modules

per-defined modules : the module create by python.org that is call per-defined modules, for example re,abc,time,threading,os

user defined modules : the module create by user that is call user-defined modules

three way to access other modules data in python

  • access the function by using module name
  • access the function directly
  • access all function,access directly

First Way:

this source file save as a10.py that is call modules name

def openTickets(message):
	return message;
def closeTickets(message):
	return message;

this source file save as b10.py that is call modules name

import a10
print(a10.openTickets("ticket range"))
print(a10.closeTickets("ticket close"))
ticket range
ticket close

Second Way:

this source file save as a10.py that is call modules name

def openTickets(message):
	return message;
def closeTickets(message):
	return message;

this source file save as b10.py that is call modules name

from a10 import openTickets,closeTickets
print(openTickets("ticket range"))
print(closeTickets("ticket close"))
ticket range
ticket close

Third Way:

if you have multiple method.then this approach good

this source file save as a10.py that is call modules name

def openTickets(message):
	return message;
def closeTickets(message):
	return message;

this source file save as b10.py that is call modules name

from a10 import * 
print(openTickets("ticket range"))
print(closeTickets("ticket close"))
ticket range
ticket close

Different modules name with same methods

this source file save as a10.py that is call modules name

def openTickets(message):
	return message;

this source file save as c10.py that is call modules name

def openTickets(message):
	return message;

this source file save as b10.py that is call modules name

#First Approach
import a10
import c10
print(a10.openTickets("A10 : ticket range"))
print(c10.openTickets("C10 : ticket range"))

#Second Approach
from a10 import openTickets
from c10 import openTickets
print(openTickets("A10 : ticket range"))
print(openTickets("C10 : ticket range"))

#Third Approach
from a10 import *
from c10 import *
print(openTickets("A10 : ticket range"))
print(openTickets("C10 : ticket range"))
A10 : ticket range
C10 : ticket range
A10 : ticket range
C10 : ticket range
A10 : ticket range
C10 : ticket range

Different modules name with class and same methods

this source file save as a10.py that is call modules name

class sbi:
	def getBankName(self,name):
		return name;

this source file save as c10.py that is call modules name

class pnb:
	def getBankName(self,name):
		return name;

this source file save as b10.py that is call modules name

#First Approach
import a10
import c10
obj1=a10.sbi()
obj2=c10.pnb()
print(obj1.getBankName("PNB"))
print(obj2.getBankName("SBI"))

#Second Approach
from a10 import sbi
from c10 import pnb
obj3=a10.sbi()
obj4=c10.pnb()
print(obj3.getBankName("PNB"))
print(obj4.getBankName("SBI"))

#Thrid Approach
from a10 import *
from c10 import *
obj5=a10.sbi()
obj6=c10.pnb()
print(obj5.getBankName("PNB"))
print(obj6.getBankName("SBI"))
PNB
SBI
PNB
SBI
PNB
SBI