Electronic cook book

(python question)

Page 1 of 1

5 Replies - 1666 Views - Last Post: 01 February 2010 - 01:59 PM Rate Topic: -----

#1 Eric115  Icon User is offline

  • coderさん
  • member icon

Reputation: 63
  • View blog
  • Posts: 696
  • Joined: 19-January 09

Electronic cook book

Posted 29 January 2010 - 02:00 AM

Hello there! the other day i began to use what skills i have to write a very basic 'cook book' for the computer. I am only fairly new to python but i planned this to be simple and then i would update it as i go. Basicly i am having a few problems which i can't seem to find a sulotion to...

- When the user currently searches something, it searches a list, i was wondering if i could use a database or a library as a more 'efficent' way to search than a list, but i don't know how i could do this.

-I plan to have the cookbook import a description of the recipe and then ask the user if they want to continue(I can do) but i don't know how to import something depending on something else e.g. the user selects a milkshake, how do i import milkshake.py without physically programming import milkshake.py i tried using stuff like a variable".py" but that didn't work. I am using easygui.choicebox to show the search results.

-Also with the search at the moment the search has to be exact to the recipe in the list. Is there a way they can mispell a recipe or write in a keyword and get a bunch of suggestions as to what they might of ment?

Here is my code:
import easygui, sys
def searchRes(search, recipes):
	if search in recipes:
		easygui.choicebox(msg ="Select a recipe", choices = (search, ""))
	elif search not in recipes:
						  easygui.msgbox("The recipe was not found!")
						  seaExi = easygui.boolbox("Would you like to search again or Exit?", choices =("Search again", "Exit"))
						  if seaExi == 0:
							  sys.exit()
						  elif seaExi == 1:
							  search()

def recomend(quickRec):
						  easygui.choicebox("have a look at today's recomendations!", title = "Easy Menu",
											choices =(quickRec))

def search():
	search = easygui.enterbox("Enter recipe to search for it: ")
	searchRes(search, recipes)

recipes = ['hamburgers', 'chicken kievs', 'milkshake', 'banana milkshake']
quickRec = ['hamburgers', 'chicken kievs', 'milkshake', 'banana milkshake']
easygui.msgbox("Welcome to Easy Menu", title='Easy Menu', image='easymenu_logo.gif')
searRec = easygui.boolbox("Would you like to search for a recipe or look at some recomendations?",
						 choices =("Search", "view recomendations"))
if searRec == 1:
	search()
	searchRes(search, recipes)
elif searRec == 0:
	recomend(quickRec)


I was planning to have the recipes as a separate program altogether or in a .txt file (.txt file might be easier(i guess i could use a module for that))
but also if anyone can shed some light on what would be best for that area, that would be great!

Thank you in advance :D :^:
p.s. any suggestions are greatly welcomed. Also if you need anything else just let me know thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Electronic cook book

#2 chemicalfan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 88
  • Joined: 16-October 09

Re: Electronic cook book

Posted 29 January 2010 - 05:31 AM

Depending on how big it gets, I'd definately use an SQL database or a txt/csv file to store the data in. I'd also suggest that you use a dictionary rather than a list to store the data, as I believe they perform better (I think!!!)

An SQL database is dead easy to link into Python code, but you'll need to know SQL first. If you don't (and don't want to learn it), go with a CSV file for storage. Check out the CSv module (it's pretty easy once you get your head round the 'file object' thing)
Was This Post Helpful? 0
  • +
  • -

#3 Eric115  Icon User is offline

  • coderさん
  • member icon

Reputation: 63
  • View blog
  • Posts: 696
  • Joined: 19-January 09

Re: Electronic cook book

Posted 29 January 2010 - 07:59 PM

Thanks i'll take a look at SQL and csv! Any ideas on the searching or would that be encoded using SQL or csv?
Was This Post Helpful? 0
  • +
  • -

#4 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Electronic cook book

Posted 29 January 2010 - 08:09 PM

Using a CSV (comma separated value) file would be more trivial to parse than SQL, as it is only a text file with its values separated by commas (although, the syntax is slightly more complex than that)

Check out the Wiki page for information http://en.wikipedia....eparated_values
Was This Post Helpful? 0
  • +
  • -

#5 chemicalfan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 88
  • Joined: 16-October 09

Re: Electronic cook book

Posted 01 February 2010 - 01:39 AM

The problem with CSV, is that it's a simple file stored on the system. Anyone can edit/delete it outside of the program, so it's really insecure (assuming no user security). SQL databases have a lot more security built-in by default, but there is an overhead associated with the SQL engine. Running a database where there is only one concurrent user (i.e. only one person connected at once to the database) running a single query is a waste of time, as it's not worth the database engine overhead
Was This Post Helpful? 0
  • +
  • -

#6 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Electronic cook book

Posted 01 February 2010 - 01:59 PM

I'm personally very fond of SQLite. It's easy to use and highly portable. Python and SQLite work together very nicely. I created a program to store user names and passwords using Python + SQLite and it worked out terrificly.

-Adam
http://www.learningp...rogramming.com/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1