| | |
Virtual Address Book Help
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 26
Reputation:
Solved Threads: 1
I'm currently trying to make an address book that can store data in a .txt file.
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
Python Syntax (Toggle Plain Text)
print "Virtual Address Book" print "Austin Jackson; Project 4 : Jun 14, 2008" print " " print "1. Add New Contact Information" print "2. View Adress Book" choice = input(">") if choice == 1: name = raw_input("Contacts Name:") address = raw_input("Contacts Address:") number = raw_input("Contacts Number:") email = raw_input("Contacts Email:") out_file = open("address.txt", "w") out_file.write("Contacts Name: ") out_file.write(name + "\n") out_file.write("Contacts Address: ") out_file.write(address + "\n") out_file.write("Contacts Number: ") out_file.write(number + "\n") out_file.write("Contacts Email: ") out_file.write(email + "\n") out_file.close() if choice == 2: in_file = open("address.txt", "r") text = in_file.read() 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
•
•
Join Date: Dec 2006
Posts: 1,008
Reputation:
Solved Threads: 285
•
•
•
•
out_file = open("address.txt", "w")
out_file = open("address.txt", "a")
You want to "a"=append to, not "w"=write over. And to start you out
Python Syntax (Toggle Plain Text)
if choice == 2: in_file = open("address.txt", "r") text = in_file.readlines() in_file.close() print text
![]() |
Similar Threads
- Need help with Address book (C++)
- trojans...now nothing opens and I get a paint can't open error (Viruses, Spyware and other Nasties)
- [Win32/C++] Listview question (C++)
- Hijackthis report, I just don't know (Viruses, Spyware and other Nasties)
- Linker Error in derived class initialization (C++)
- HELP With functions (C++)
Other Threads in the Python Forum
- Previous Thread: regular expressions
- Next Thread: Simple wxQuestion
| Thread Tools | Search this Thread |
accessdenied advanced aliased argv beginner bits calling casino change command convert count csv cturtle cursor def dictionary digital dynamic dynamically enter event examples external file float format frange function google gui hints homework i/o iframe import input jaunty java keyboard lapse line linux list lists loop microphone mouse movingimageswithpygame multiple newb number numbers obexftp output parameters parsing path port prime programming projects py py2exe pygame pygtk pyopengl python random recursion remote return reverse scrolledtext session signal simple skinning sprite string strings syntax terminal text threading time tkinter tlapse tuple tutorial ubuntu unicode unit urllib urllib2 variable voip web-scrape whileloop wxpython






