
from Globals import MAX

class MyContacts:
    # Modified
    def __init__(self):
        self.FILENAME = "contacts.txt"
        self.FILE_MODE = "r"
        self.permContactList = []
        self.readFromFile()
        # (No 'self') Only a local not attribute
        copyContacts = []  
        i = 0
        while (i < len(self.permContactList)):
            copyContacts.append(self.permContactList[i])
            i = i + 1 


    # No change
    def displayContacts(self):
        i = 0
        while (i < len(self.permContactList)):
            print(self.permContactList[i])
            i = i + 1

    # NEW
    def displayCopyContacts(self):
        print("Uncomment below to see error")
        # print(copyContacts)  # Can't access init's local    
        # print(self.copyContacts)  # Self won't work, not attribute

    # Error: jt and tj are local to start() can't access here
    # Uncomment below to see errors
    def erroneousDisplay(self):
        i = 0
        print("Can't see jt and tj, uncomment loops to see")
        #while (i < len(jt.permContactList)):
        #    print(jt.permContactList[i])
        #    i = i + 1

        #while (i < len(tj.permContactList)):
        #    print(tj.permContactList[i])
        #    i = i + 1
        
        #No attributes named jt and tj
        #Can't be accessed this way
        #self.jt = self.tj


    # No change
    def readFromFile(self):
        done = False
        count = 0
        inputFile = open(self.FILENAME,self.FILE_MODE)
        # Notice how the display is double spaced (one newline
        # from print() the other is read in from the file).
        while (done == False):
            line = inputFile.readline()
            if ((line == "") or (count >= (MAX))):
                done = True
            else:
                self.permContactList.append(line)
                count = count + 1
        inputFile.close()
    
    # New
    def copyContacts(self):
        # Only creates a local copyContacts, can’t see outside this method
        copyContacts = []
        i = 0
        while (i < len(self.permContactList)):
            copyContacts.append(self.permContactList[i])
            i = i + 1


        
