First of all, the important parts of the code...
and...
When you run the code and run into a name that's already on file, you get the option to go onto the edit section of the code. When you do this, though, the program always gets the EOFError. I'm guessing the data in the file is deleted (or moved directly to? excuse my ignorance) when it's moved into memory. It's not put back until you leave both functions. I'm not sure how to get around this.
The other problem is that on my school computer, it doesn't recognize 'address.txt' as being there. I keep getting this message:
But I think this probably has something to do with the way the cmd prompt is setup...
Code:
def AddressRW(aw, ar):
#For Reading & Writing to address file
while aw == True:
try:
#(W)right
adDict = {}
adFile = file('address.txt', 'r')
adDict = Dill.load(adFile)
adFile = file('address.txt', 'w')
newName = raw_input("Enter name of resident: ")
if adDict.has_key(newName):
adFile.close
ynTest = True
while ynTest == True:
overChoice = raw_input("Name already in list. Rewright? (y,n)")
if overChoice == 'y' or overChoice == 'Y':
aw = False
ynTest = False
AddressAP(True, False, False)
elif overChoice == 'n' or overChoice == 'N':
aw = False
ynTest = False
else:
print "...Error - Try Again..."
else:
adDict[newName] = raw_input('Enter Address in desired format: ')
Code:
def AddressAP(edit, delete, search):
#For searching, editing, and deleting address names
while edit == True:
try:
adDict = {}
adFile = file('address.txt', 'r')
adDict = Dill.load(adFile)
adFile = file('address.txt', 'w')
dictSearch = raw_input("Whose address do you want to edit? ")
if adDict.has_key(dictSearch):
adDict[dictSearch] = raw_input("What is the new address? ")
Dill.dump(adDict, adFile)
adFile.close
edit = False
else:
print "Name not on file."
edit = False
except EOFError:
print "No addresses on file..."
edit = False
When you run the code and run into a name that's already on file, you get the option to go onto the edit section of the code. When you do this, though, the program always gets the EOFError. I'm guessing the data in the file is deleted (or moved directly to? excuse my ignorance) when it's moved into memory. It's not put back until you leave both functions. I'm not sure how to get around this.
The other problem is that on my school computer, it doesn't recognize 'address.txt' as being there. I keep getting this message:
Code:
Traceback (most recent call last):
File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\student4\Desktop\Python Programs\Addressbook\addressbook.py.py", line 140, in ?
AddressRW(False, True)
File "C:\Documents and Settings\student4\Desktop\Python Programs\Addressbook\addressbook.py.py", line 53, in AddressRW
adFile = file('address.txt', 'r')
IOError: [Errno 2] No such file or directory: 'address.txt'
Comment