Virtual Address Book Help

Thread Solved

Join Date: Jun 2008
Posts: 26
Reputation: inkcoder is an unknown quantity at this point 
Solved Threads: 1
inkcoder inkcoder is offline Offline
Light Poster

Virtual Address Book Help

 
0
  #1
Jun 14th, 2008
I'm currently trying to make an address book that can store data in a .txt file.

  1. print "Virtual Address Book"
  2. print "Austin Jackson; Project 4 : Jun 14, 2008"
  3. print " "
  4. print "1. Add New Contact Information"
  5. print "2. View Adress Book"
  6. choice = input(">")
  7.  
  8. if choice == 1:
  9. name = raw_input("Contacts Name:")
  10. address = raw_input("Contacts Address:")
  11. number = raw_input("Contacts Number:")
  12. email = raw_input("Contacts Email:")
  13.  
  14. out_file = open("address.txt", "w")
  15. out_file.write("Contacts Name: ")
  16. out_file.write(name + "\n")
  17. out_file.write("Contacts Address: ")
  18. out_file.write(address + "\n")
  19. out_file.write("Contacts Number: ")
  20. out_file.write(number + "\n")
  21. out_file.write("Contacts Email: ")
  22. out_file.write(email + "\n")
  23. out_file.close()
  24.  
  25. if choice == 2:
  26. in_file = open("address.txt", "r")
  27. text = in_file.read()
  28. in_file.close()

That is what I have so far. I have two problems:
1. Every time I enter a new contact the previous contact gets over written.
2. I cannot display my address (choice 2)... Though I think my code is correct...

Help would be appreciated,
Austin
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,008
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 285
woooee woooee is offline Offline
Veteran Poster

Re: Virtual Address Book Help

 
0
  #2
Jun 14th, 2008
out_file = open("address.txt", "w")
Change this to
out_file = open("address.txt", "a")
You want to "a"=append to, not "w"=write over. And to start you out
  1. if choice == 2:
  2. in_file = open("address.txt", "r")
  3. text = in_file.readlines()
  4. in_file.close()
  5. print text
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 26
Reputation: inkcoder is an unknown quantity at this point 
Solved Threads: 1
inkcoder inkcoder is offline Offline
Light Poster

Re: Virtual Address Book Help

 
0
  #3
Jun 15th, 2008
Thanks for you help this solved my problem!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC