-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.py
71 lines (62 loc) · 1.65 KB
/
contact.py
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
66
67
68
69
70
71
import pyperclip
class Contact:
"""
Class that generates new instances of contacts
"""
# Class variables
contact_list = [] # empty contact list
def __init__(self,first_name,last_name,phone_number,email):
'''
__init__ method helps us define
properties for our objects
'''
# Instance Variables
self.first_name = first_name
self.last_name = last_name
self.phone_number = phone_number
self.email = email
def save_contact(self):
'''
save_contact method saves contact objects into contact_list
'''
Contact.contact_list.append(self)
def delete_contact(self):
'''
delete_contact method deletes a saved contact from the contact_list
'''
Contact.contact_list.remove(self)
@classmethod
def find_by_number(cls,number):
'''
Method that takes in a number and returns a contact that matches that number.
Args:
number: Phone number to search for
Returns :
Contact of person that matches the number.
'''
for contact in cls.contact_list:
if contact.phone_number == number:
return contact
@classmethod
def contact_exist(cls,number):
'''
Method that checks if a contact exists from the contact list.
Args:
number: Phone number to search if it exists
Returns :
Boolean: True or false depending if the contact exists
'''
for contact in cls.contact_list:
if contact.phone_number == number:
return True
return False
@classmethod
def display_contacts(cls):
'''
method that returns the contact list
'''
return cls.contact_list
@classmethod
def copy_email(cls,number):
contact_found = Contact.find_by_number(number)
pyperclip.copy(contact_found.email)