Skip to content

Commit ed29119

Browse files
modules added
1 parent 2222763 commit ed29119

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

modules.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Diving into modules
2+
3+
'''
4+
Modules can be imported in the following ways:
5+
6+
1. import module_name
7+
This will import the mosule but if when you will use the function from the module,
8+
you have to specify the module_name with the function. e.g: user_module.function1()
9+
10+
2. import module_name as short_name
11+
This is exactly similar to the previous method. The only difference is that instead
12+
of writing the module_name again you can use the short_name you gave.
13+
e.g: import user_module as um
14+
um.function1()
15+
16+
3. from module_name import function
17+
This will import only the specific function from the given module. You cannot use other
18+
functions from that module.
19+
e.g: from user_module import function1
20+
function1()
21+
22+
4. from module_name import *
23+
This will import all the functions from the module. Additionally you will not need to
24+
write the module_name anymore for accessing the functons.
25+
e.g: from user_module import *
26+
function1()
27+
28+
'''
29+
30+
#import user_module
31+
#import user_module as um
32+
#from user_module import functon1
33+
from user_module import *
34+
import random
35+
36+
37+
functon1()
38+
functon2()
39+
40+
41+
x = random.randrange(1,100) #it will generate a random number within 1 to 100. Function imported from random module.
42+
print(x)
43+
44+
# dir(module_name)
45+
# help(mosule_name)
46+
47+
# The following will show the dir where python search for modules
48+
import sys
49+
print(sys.path)
50+
51+
#sys.path.append("your_module_path") this will add your own module path to predefines paths od python modules

user_module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This a user created module having two functions
2+
3+
def functon1():
4+
print("Function1 Imported Successfully")
5+
6+
def functon2():
7+
print("Function2 Imported Successfully")

0 commit comments

Comments
 (0)