Advise of programming one of my first programs

Anatoli Hristov tolidtm at gmail.com
Mon Mar 26 17:53:54 EDT 2012


Hi guys just wanted to share one of my first programs. Could you please
tell me, do I use a right logic ?
It works fine what I wanted to do, but is it writen in the right way? My
next step is to make it write the changes of the dictionary on the file :)
## DB
tbook = {'goodie':['Christian','Van Eckel','Bruxelles','Forest','02 344 33
33','This is a test note :)'],
 'osvaldo':['Osvaldo','Rios','Liege','Centrum','023758832',''],
 'ronaldo':['Diego','Aspanda','Brussels','Vorst','03 443 23 23','']}
## Edit selected nickname
def edit():
 sb = tbook[select]
 fn = raw_input('New name for ' + sb[0] + ' : ')
 sb[0] = fn
 ln = raw_input('New name for ' + sb[1] + ' : ')
 sb[1] = ln
 raw_input('\n\n\nPress <Enter> to return')
 details()
## Details of nickname
def details():
 sb = tbook[select]
 print 'Nickname: ', select, ' is selected\n'
 print 'First name:\t', sb[0], '\n'
 print 'Last name:\t', sb[1], '\n'
 print 'Country:\t', sb[2], '\n'
 print 'City:\t\t', sb[3], '\n'
 print 'Phone number:\t',sb[4], '\n'
 print 'Memos:\n'
 print sb[5]
 print '\n\n(E)dit\n\n'
 print '(B)ack to phonebook list\n\n'
 menu = raw_input('What you wana do? ')
 if menu == 'e':
 edit()
 if menu == 'b':
 listpb()
## Select nickname
def selectm():
 global select
 select = raw_input('Type nickname and press <Enter>: ')
 if select == '':
 listpb()
 if select in tbook:
 details()
 else:
 listpb()
## List all contacts
def listpb():
 print '_' *45, ' Phonebook ', '_' *45,'\n\n\n'
 print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel'
 print '_' * 105,'\n','\t' * 13
 for val in tbook.keys():
 print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t',
tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n'
 print '_'*105,'\n\n'
 selectm()
## Call list names
listpb()
Thanks a lot
Anatoli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120326/64cd3bb4/attachment.html>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /