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
#!/usr/bin/python
# Filename: codi.py
################ COmpany DIrectory ################

while True:
    ui = raw_input('#> ') # ui for user input
    if ui in ('quit', 'exit'):
        print 'Goodbye.' 
        break
    if ui == 'help':
        print 'Options: help, search, add, remove, quit'
        continue
    if ui == 'add':
        coname = raw_input('Type in company name: ')
        phnumber = raw_input('Type in company phone number: ')
        addin = coname + ' ' + phnumber
        myList = addin
        f = open('codilist.txt', 'a') # open for 'w'riting. 'r' is for reading.  'a' is for append.
        f.write('\n' + myList) # write user input to list
        f.close() # close the file
        continue
    if ui == 'remove':  
        coname = raw_input('What company do you want to remove? ') # company name
        f = open('codilist.txt', 'r') # original phone number listing        
        f1 = open('codilist.tmp', 'a') # open a tmp file

        for line in f:  # THIS IS WHERE I NEED HELP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<,
            if line.strip() == coname.strip():  # a match! don't add this line, but add the rest of the file
                for line in f:
                    # write remaining lines
                    f1.write(line)                             
                break         # WILL LATER OVERWRITE THE codilist.txt WITH THE TMP FILE
            else:
				f1.write(line)
        else:
            print 'Error: That company is not listed.'    
        f1.close()
        f.close()
        continue
    if ui == 'search':
        usearch = raw_input('What company do you want to look for? ') # user search
        with open('codilist.txt') as f:
            line = f.readline()
            for line in f:
                if usearch in line:
                    print line
                    break
            else:
                print 'Company name is not listed.'
        f.close() # close the file
        continue

This paste never expires. View raw. Pasted through import.