-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.py
More file actions
54 lines (44 loc) · 1.55 KB
/
message.py
File metadata and controls
54 lines (44 loc) · 1.55 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
"""
message.property
Contains the message class to handle messages from the files
"""
class Message:
"""
Contains a message the can be printed out to the screen
"""
def __init__(self, message_string):
"""
Creates an instance of messsage
Arguments:
message_string: string containing the message
to be displayed
Returns:
instance of message
"""
self.message_string = message_string
def print_message(self):
"""
Prints the message to stdout
"""
print("This is the class message {}".format(self.message_string))
def __str__(self):
"""
Overrides the str operator to print a pretty string
"""
return "This is overriding the str class of the fuction: {}".format(self.message_string)
def __add__(self, msg):
"""
Overrides the add operator to either add a Message or string
Arguments:
msg - A Message instance or string that is to be added
Returns:
New Message instance with msg added to the message_string
"""
if isinstance(msg, str):
r_msg = Message(self.message_string + msg)
elif isinstance(msg, Message):
r_msg = Message(self.message_string + msg.message_string)
else:
raise TypeError("Class Message does not know how to add" +
"a variable of type {}".format(type(msg)))
return r_msg