-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmymodule.py
More file actions
65 lines (47 loc) · 1.34 KB
/
Copy pathmymodule.py
File metadata and controls
65 lines (47 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#-------------------------------------
# Create a Module (mymodule.py)
#-------------------------------------
# Save this code in a separate file named: mymodule.py
# def greeting(name):
# print("Hello, " + name)
# person1 = {
# "name": "John",
# "age": 36,
# "country": "Norway"
# }
#-------------------------------------
# Use a Module
#-------------------------------------
import mymodule
# Call the greeting function from the module
mymodule.greeting("Jonathan")
#-------------------------------------
# Variables in Module
#-------------------------------------
# Access the dictionary from the module
x = mymodule.person1["age"]
print(x)
#-------------------------------------
# Re-naming a Module using alias
#-------------------------------------
import mymodule as mx
a = mx.person1["age"]
print(a)
#-------------------------------------
# Built-in Modules
#-------------------------------------
import platform
# Use a function from the platform module
x = platform.system()
print(x)
#-------------------------------------
# Using the dir() Function
#-------------------------------------
# List all functions and variables in the platform module
x = dir(platform)
print(x)
#-------------------------------------
# Import From Module
#-------------------------------------
from mymodule import person1
print(person1["age"])