__author__ = "Narendra Boyina"
# -----------------------------------------------------------------------------
# Copyright (c) 2025 BR Technologies PVT LTD
# -----------------------------------------------------------------------------
"""
Topics to be covered in today's class:
--> What is module and purpose of module ?
--> Types of module
--> Different ways to utilize modules along with examples
"""
"""
Module: • Python module is nothing but a python file(the .py extension)
=======
• purpose of Modules : for using the functions, classes methods defined in another file, in the current python file
We are having 3 types of modules in python
1. User defined modules (we need to create these modules)
2. Internal modules ( During installation of python interpreter these modules will be installed on your machine))
3. External modules (We need to install these modules, if required) Ex: xlrd/xlwt/pyserial/pandas/numpy/
# In linux flavour operating systems ()
# =======================================
# module install
# pip3 install module_name
# python -m pip install module_name
# module uninstall
# pip3 uninstall module_name
# python -m pip uninstall module_name
# =======================================
# module upgrade
# python -m install --upgrade module name
# ========================================
pip3 list --> this command will display all the modules installed on your server/ machine
=======================
Different ways to utilize modules
1. import module_name
2. from module_name import function
3. from module_name import function_1, function_2, ..., funcetion_n
4. from module_name as alias_name (or) short_name
5. from module_name import function as alias_name (or) short_function_name
6. from module_name import *
7. from directory_name import module_name
8. from directory_name.module_name import function
9. from directory_name.module_name import function1, function2,... function_n
10. from directory_name.module_name import function_name as alias_name (or) short_name
11. from directory_name.module_name import function_names as alias_names (or) short_names
12. from directory_name.module_name import * (all functions)
13. from directory_name.module_name import class_name
14. from directory_name.module_name import class_name1, class_name2, ...class_name_n
15. from directory_name.module_name import * (importing all class, functions and all )
16. from directory_name.module_name import class_name as alias_name (or) short_name
17. from directory_name.module_name import class_names as alias_names, function_names as alias_name
Note: dir(module_name) --> this will give list of all available functions in the specific module.
Example: print(dir(string))
"""
# python inbuilt functions ()
# len()
# type()
# id()
# print()
# help() # it gives the complete documentation of any function/ module.
# min()
# max()
#int()
#float()
#tuple()
#string()
#dict()
# list()
# range()
import string, calendar, time, os, sys
# print(dir(string))
# print(help(string))
# print(dir(calendar))
# print(help(calendar))
""" 1. import module"""
import Narendra # importing all functions & all classes defined inside Narendra file
Narendra.Bhagyasree()
# Narendra.add(255, 166)
# Narendra.printinfo(2, 3, 4, 5,9)
# Narendra.printinfo(4, 5, 6)
# Narendra.printinfo(8, 6, 3)
# Narendra.printinfo(18, 6, 31, 77, 99)
"""2. from module_name import function_name"""
from Narendra import printinfo
# printinfo(2, 3, 4, 5,9)
# printinfo(4, 5, 6)
# printinfo(8, 6, 3)
"""3. from module_name import function_1, function_2, ..., funcetion_n"""
from Narendra import printinfo,Bhagyasree
# Bhagyasree()
# printinfo(2,3)
# printinfo(3,4,6,7)
# Bhagyasree()
# Providing alias name for the module
"""4. module_name as alias_name (or) short_name"""
import Narendra as N
# N.printinfo(2,3,4,5,6)
# N.Bhagyasree()
# N.add(33,22)
"""5. from module_name import function as alias_name (or) short_function_name"""
# Providing alias name for the function
from Narendra import printinfo as pi
# pi(1,5,7,7)
# pi(3,6,7,8)
"""6. from module_name import *"""
from Narendra import *
# printinfo(123, 456, 22, 33)
# add(2, 3)
# add(33, 33)
# Bhagyasree()
# abc()
""" 7. from directory_name import module_name"""
from Class_18_Functions_3 import Functions_3
#
# Functions_3.cal(1, 2, 3)
# Functions_3.cal(11, 22, 33)
# Functions_3.cal(44, 52, 23)
#
""" 8. from directory_name.module_name import function_name """
from Class_18_Functions_3.Functions_3 import cal
# cal(1, 2, 3)
# cal(11, 22, 33)
# cal(44, 52, 23)
"""9. from directory_name.module_name import function1, function2,... function_n"""
from Class_18_Functions_3.Functions_3 import cal, respective_data
# cal(11, 22, 33)
# cal(4, 2.50, 3)
# respective_data(14, 2.5, 4,"Data", name="narendra") # it will give error, Reason: you have provided 2 values for x
# respective_data(14, 2.5, 77, "Data", qualification="M.tech", designation="Team lead")
"""10. from directory_name.module_name import function_name as alias_name (or) short_name"""
from Class_18_Functions_3.Functions_3 import respective_data as rd
#
# rd(14, 2.5, 4,"Data", name="narendra") # it will give error, Reason: you have provided 2 values for x
# rd(14, 2.5, 77, "Data", qualification="M.tech", designation="Team lead")
"""11. from directory_name.module_name import function_names as alias_names (or) short_names"""
from Class_18_Functions_3.Functions_3 import cal as c, respective_data as rd
# c(11, 22, 33)
# c(21, 22, 23)
# rd(14, 2.5, 77, "Data", qualification="M.tech", designation="Team lead")
""" 12. from directory_name.module_name import * (importing all functions from a file(module) present in another directory)"""
from Class_18_Functions_3.Functions_3 import *
# cal(21, 22, 23)
# respective_data(14, 2.5, "Data", qualification="M.tech",Designation="Team Lead")
# required_factorial_number = int(input("Enter a numerical value for factorial: ")) # factorial of given input value
# print("The factorial of {0} is {1} ".format(required_factorial_number, calc_factorial(required_factorial_number)))
"""13. from directory_name.module_name import class_name (importing class ) """
from Class_26_OOPs_3.OOPS_3 import Employee
# emp1_obj = Employee("Narendra", 34000) # creating object for Employee class, So constructor(__init__) method will execute
# emp1_obj .displayEmployee() # calling the method present in Employee class by using obj
# emp1_obj .displayCount() # calling the method present in Employee class by using obj
# emp1_obj .name = "Kruthika" # modifying existing attribute's value
# emp1_obj .salary = 45000 # modifying existing attribute's value
# emp1_obj .qualification = "B.Tech" # adding new attribute
# print(emp1_obj.name, emp1_obj.salary, emp1_obj.qualification)
#
# emp2_obj = Employee("swetha", 52000) # creating 2nd object for the same class
# print(emp2_obj.name, emp2_obj.salary)
"""14. from directory_name.module_name import class_name1, class_name2, ...class_name_n"""
from Class_26_OOPs_3.OOPS_3 import Employee, BankAccount
# emp1_obj = Employee("Narendra", 34000) # crating object for Employee class, So constructor(__init__) method will execute
# emp1_obj .displayEmployee() # calling the method present in Employee class by using obj
# emp1_obj .displayCount() # calling the method present in Employee class by using obj
#
# account = BankAccount("varun")
# account.deposit(50000)
# account.deposit(3000)
# account.withdraw(2000)
"""15. from directory_name.module_name import * (importing all functions, and all classes )
Note: functions you can call directly after importing,
but you have to create instance for the classes to call the class attributes and methods"""
from Class_26_OOPs_3.OOPS_3 import *
# utilizing the functions
unique_list([5, 3, 1, 3, 4, 5, 6, 6, 68, 8, 8, 8, 68])
# utilizing the classes
# emp1_obj = Employee("Narendra", 34000) # crating object for Employee class, So constructor(__init__) method will execute
# emp1_obj .displayEmployee() # calling the method present in Employee class by using obj
# emp1_obj .displayCount() # calling the method present in Employee class by using obj
#
# account = BankAccount("varun")
# account.deposit(50000)
# account.deposit(3000)
# account.withdraw(2000)
"""16. from directory_name.module_name import class_name as alias_name (or) short_name"""
from Class_25_OOPS_2.Class_2 import Salary_hike as sh
Sh_obj = sh("HM0002162", 2, 32000, "c2", "star") # crating object, (__init__) method will execute
print(Sh_obj.EmpID, Sh_obj.Level)
"""17. from directory_name.module_name import class_names as alias_names, func_names as alias_names"""
from Class_25_OOPS_2.Class_2 import Salary_hike as sh, calc_factorial as fact
#
Sh_obj = sh("HM0002162", 2, 32000, "c2", "star") # crating object, (__init__) method will execute
print(Sh_obj.EmpID, Sh_obj.Level)
fact(6)==================================================================================
PART -2==================================================================================
__author__ = "Narendra Boyina"
"""
This is a User defined module
performs following functions
[addtion]
"""
def Bhagyasree(): # function without arguments
print("W/o Narendra Boyina")
print("Completed M.tech")
print("Simple,obedient and Understanding Nature")
def add(a,b): # function with arguments
"""
this function is useful for adding 2 values
:param a:
:param b:
:return: return addition value
"""
c = a +b
print(c)
return c
def abc(c, d, a=24,b=10):
"""
This function performs
:param c:
:param d:
:param a:
:param b:
:return:
"""
print(a,b,c,d)
return
# abc(12,24,13,15)
def printinfo(arg1, *vartuple):
"""
this function performs variable length arguments
other than 1st argument's value, remaining values will be stored in tuple
:param arg1:
:param vartuple:
:return:
"""
print ("arg is: ", arg1)
print ("arg is: ", vartuple)
# for var in vartuple:
# print ("Varible length arg is",var)
return
# # Now you can call printinfo function
# printinfo() # TypeError: printinfo() missing 1 required positional argument: 'arg1'
# printinfo(10)
# printinfo(60, 70)
# printinfo(50, 60, 70)
# printinfo(50, 60, 70,49,30,279,467,78, 67.87)
#
# a=[10,23,56,78]
# b=list(a)
# print(b)
# a[3]=95
# # a[1]=34
# print(b)
def m(list):
v = list[0]
for e in list:
if v > e:
v = e
return v
#
#
# values = [[3, 4, 5, 1], [33, 6, 1, 2]]
#
# for row in values:
# print(m(row), end=" ")
#
# print("my friend name is{}, his age is".format("Narendra",28))
# print("D", end = ' ')
# print("C", end = ' ')
# print("B", end = ' ')
# print("A", end = ' ')
#
# print(format("Welcome", "10s"), end = '#')
# print("abef".replace("cd","12"))Author: Boyina Narendra
Supporting Author: M. Meera Sindhu
Request: If you find this information useful, please provide your valuable comments
No comments:
Post a Comment