Data Coding suggestions
steve at holdenweb.com
Fri Feb 27 08:27:53 EST 2009
> Just learning Python and have a project to create a weekly menu and a
> shopping list from the menu. This is something I do manually now, so
> I'm automating it.
> What I'd like is a list of menu choices, such as:
> CODE- Description - Est Cost
> 'B01 - Pancakes, Sausage,and Eggs - $5.80,
> 'L01 - Tuna Fish sandwices and chips -$ 4.25 ,
> 'D01 - Dirty Rice and Garlic Bread' - $5.70.
>>From the choices, I'll create a weekly menu, print the menu, and then
> print list of ingredients ( and sum the commom items)
> CODE- Item - Qty. - Unit
> B01 - pancake mix - 1 - box
> B01 - milk - .3 -gal
> B01 - eggs - 10 - each
> D01 - dirty rice mix - 1 - box
> D01 - milk - .3 - gal.
> I would like to expand the ingredient list to include other fields
> like 'last purchase date' and 'reorder point'.
> I've used an example program and started to code it but just realized
> I've been coding ABAP in Python, that is set up a data structure and
> use that. What I want is to learn code Python in Python.
> Question: How should I set up the data? I'm looking at maybe 70 menu
> items and maybe 1000 items for the shopping list. I need to be able
> to maintain each item also.
> I am using python 2.6 but would like to use 3.0.
Well from the nature of the task it seems evident that the data should
be long-lived, and therefore need to be stored on disk. The natural way
to deal with them in the program would be to have recipes, each of which
was associated with a number of ingredient requirements, each of which
was associated with an ingredient.
That way, you can adjust the prices of your ingredients as the market
Recent versions of Python come with sqlite, a low-cost but surprisingly
efficient relational database implementation. I'd suggest using that,
with the following tables:
id integer primary key
id integer primary key
unit string [oz, gal, etc.]
cost number [cost per unit]
recipe integer [id of recipe]
ingredient integer [id of ingredient]
quantity number [amount required for one serving]
So each recipe will have one row in the recipe table, a number of rows
in the requirement table, each of which points also to the relevant
>From there it's a relatively simple task to work out how much of which
ingredients is required to create N helpings of a specific recipe, and
the cost as well.
It will mean understanding a little more about database than you perhaps
do right now, but that's a useful addition to any programmer's bag of
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list