File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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" )
You can’t perform that action at this time.
0 commit comments