[Tutor] need advice about a dictionary ({})

Jack Trades jacktradespublic at gmail.com
Sun Sep 11 04:13:32 CEST 2011


>
> Using Python 2.7 for it, it seems to work fine, except that I can't
> see how the GUI helps. It opens only when I use the g option to find
> an entry already made. Useful for editing an entry, though.
>

Well the idea would be to build the app as a full-blown GUI.  The GUI search
and edit functionality was just a proof-of-concept to show how that may
work.

I was just having some fun and seeing what I could do in less than an hour.
Turning this into a full blown app is not what I had in mind, though if you
want to build on it to learn I would be willing to help.


>
> As for the non-GUI script, I get this error no matter which choice I
> make. I'm too dumb, and have forgotten too much of Python 2.x to
> debug:
>
> ==============================
> What's next:
> (q)  Quit
> (a)  Add new Entry
> (v)  View all Entries
> (s)  General Search
> (si) Search by Initials
> (sn) Search by Name
>
> > q
> Traceback (most recent call last):
>  File "c:\P32Working\Pickles\nicks_simple_phone_book_app.py", line
> 171, in <module>
>    main_loop()
>  File "c:\P32Working\Pickles\nicks_simple_phone_book_app.py", line
> 94, in main_loop
>    > """)
>  File "<string>", line 1, in <module>
> NameError: name 'q' is not defined
> Process terminated with an exit code of 1
> ============================
>

My guess is that this has something to do with Python 3.x not having
raw_input.  Try changing the raw_input calls to input.  I don't get that
error with 2.7.



>
> > If you're talking about re-entering all your data from your file, you
> would
> > write a script to do that.
>
> Ha! I would?
>
>
Well, yeah.


A line in the file always begins with a name, with  at
> least one phone number, then if a company, the hours they are
> reachable by phone, possibly their web address, maybe an email
> address, my contact there plus maybe her secretary. If a physician,
> there might very well be his specialty, his nurse's name, mention of
> who recommended him to me, etc.


Like I said, I'd have to see the file to comment more, but it sounds like it
may be too irregular to make writing a script an easy process.  Though I
can't be sure without seeing it.  You could always enter these things by
hand...

I should probably ask; what is your goal for this app?  Is it to learn some
Python while making a usable app?  Or are you looking for a robust address
book for quick lookups of information?  If it's the latter, I'd recommend
you look around for something that's already made.  It will save you a lot
of trouble in the long run.

If you're looking for a good learning experience this kind of app is a great
starting place.  However expect to run into problems along the way, up to
and possibly beyond possibly hosing all the data you have entered into the
app.  Make regular backups of the data and keep your original around.


> It seems that the format of info for
> your way is set rigidly in advance, or am I wrong?
>
>
Not really.  Key/value pairs can be entered in arbitrary order.  I used = to
seperate key/values because that's what you used in your app and | to
seperate k/v pairs to allow spaces without quoting strings.  You could
easily replace these tokens (= or |) with whatever you want.

If you have another format that differs by more than those characters you
would need to write a different parser.  However there does have to be some
consistency to the format of your data to make parsing easier.  The less
rigid your data the more work you will have to do to parse it.  Since you
said earlier that you will probably have less than 100 entries in your phone
book, you may want to think about restructuring your data by hand to make it
easier to parse before writing your parser.

-- 
Nick Zarczynski
Pointless Programming Blog <http://pointlessprogramming.wordpress.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110910/77dd95f5/attachment.html>


More information about the Tutor mailing list