By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 2,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Writing a simple address book in python

P: 8
Hi All,
I am learning python by myself. I have some knowledge about C. But What I need to give output for an addressbook using python is(By taking user input) :

Name Mobile Address
abc 123 xyz

Further if I append some entries in the book like
mno 456 stu

I need the address book to get updated and displayed as:

Name Mobile Address
abc 123 xyz
mno 456 stu


But as I am new to python, I am not able to properly align the entries. Kindly help. The code written by me is attached. Thanks in advance for any help.

Please note: this is not a school homework!!!
Regards,
Dipak Kr. Singh
Attached Files
File Type: txt Address Book.txt (513 Bytes, 13 views)
May 4 '11 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 624
There is more than one way to format in Python. See 5.6.2 here for specific info.
Expand|Select|Wrap|Line Numbers
  1. test_list = [['abc', '123 xyz'], ['mno', '456 stu']]
  2. for person in test_list:
  3.     print "%-5s  %-10s" % (person[0], person[1]) 
May 4 '11 #2

P: 20
You can make a dictionary, the key will be the name and the value the address withing a list.
May 12 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.