Advise of programming one of my first programs

Prasad, Ramit ramit.prasad at jpmorgan.com
Tue Mar 27 11:32:39 EDT 2012


It is considered polite to post your reply either after the quoted text
or interspersed as I have done below.

> By the way I dont know why your mail was in my junk I just saw it.

Probably because I only reply back to the list and let the list 
forward to you.

> And here is my last code I did for the phonebook:
> Thanks
> 
> ####### CODE #########
> fileread = open('myfile.txt','r')
> tbook = eval(fileread.read())
> fileread.close()

The use of eval is dangerous if you are not *completely* sure what is 
being passed in. Try using pickle instead: 
http://docs.python.org/release/2.5.2/lib/pickle-example.html 


> Thank you Ramit for your advice`s. I`m reading a book ( Learning Python,
> Second Edition ) by Mark Lutz and David Ascher and now I just finished the
> Basic Function lesson :) I will keep in mind what you have advised me, but
> will implement it later when I have more experience with the book, because
> I don`t understand exactly what you mean by doing all dose changes :)

Maybe I can help you more by giving you a somewhere to build from. Try
building the rest of the program given the new version of listpb below.
You will need to read the chapter on Function Arguments (chapter 18?).

 def listpb():
     tbook = load_book()
     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'
     while True:
          choice = get_menu_choice()
          if choice == 'e' or choice == 'E':
               book = get_book_to_edit()
               edit( tbook, book )
          elif choice == 'd' or choice == 'D':
               book = get_book_to_edit()
               details( tbook, book )
          elif choice =='Q' or choice == 'q':
               break # end loop to exit program
          else:
               print 'Selection {0} not understood.'.format( choice ) 

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Python-list mailing list