![]() |
Critique my exercise
Let me start by saying that this was just an exercise that I made up for myself while learning python now that I'm a couple of weeks in. It began originally as just a means to play with dictionary variables, but I ended up adding some file i/o and error handling.
The program works exactly as it should. I've fixed all the bugs that I have found thus far... I'm just curious to see if the way I wrote this is the best (or good enough). Should I have done something differently? Is there unnecessary code? :
#!/usr/bin/python |
I don't know much about Python but I can understand the basics of what your code does. If your only a couple weeks into it, I'd say you did a great job long as you understand what it all does :) (not just cutting and pasting, but it doesn't seem that way). Good begining program ;) Nice commenting and what looks to be perfect indenting. Nice clean code, Great job dude :)
|
like booooze said that is a very nice clean looking code. i think that is great program you made just learning python.
|
Quote:
:
try:In fact, one could make it simpler still, and use the standard csv module: :
import csvThe second thing I'd do differently would be to use a dictionary instead of a lot of elif-statements: :
def add_person():The shelve module allows you to tie a dictionary to a file, such that any chance to the dictionary, is automatically saved to the file. Thus, your file reading and writing code could be replaced by two lines: :
import shelve |
somehollis,
your code is basic, uncomplicated and easy to read and understand, all in the spirit of Python! Very nice! My suggested improvement would be more on the user's side. When you add or remove an item, it would nice to add a list of recorded persons, so a mistake in typing the name could be avoided. Maybe list the recorded persons by number, so you only have to enter that number. |
Thanks for the suggestions, guys (especially Averos for pointing at some things that I didn't yet know were possible and Dietrich for the insight on the user side). Now I have something play with.
To Booooze, I just thought I'd point out that in Python, indenting is actually a required part of the syntax. Improper indents lead to error messages. A friend of mine suggested Python as a starting point for learning programming because it would teach some good coding habits, and I believe this is (in part, at least) what he was referring to. |
One I missed. The following code for choice 5:
:
for x in dbase.keys()::
for key, list in dbase.items(): |
Quote:
Good language to start with and it seems liek your taking it slowly, which is good. You don't want to be one of those people that want to dive into 3d Games right away with no experience. :p |
Quote:
Games are fun to play and all, but I'm happy to leave the making thereof to other people... :D |
| All times are GMT -5. The time now is 8:05 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC