understaning "self"



I've been searching online to try get a better understanding of what "self"
does when I define this parameter in my class functions. All I'm finding is
debates on whether "self" has any value to the language but that doesn't
help me in my newbie question. So the code excerpt below is from "Beginning
Python" Norton, Samuel, Aitel, Foster-Johnson, Richardson, Diamon, Parker,
and Roberts.

What I think "self" is doing is limiting the function call to only function
in "this" class. So in the function below "has" calls self.has_various(), if
I had a function called "has_various" in my program or another included
class using "self" insures that the "has_various" below is the one used. Am
I correct in my understanding?

thanks,

Zach-




def has(self, food_name, quantity=1):
"""
has(food_name, [quantity]) - checks if the string food_name is in the
fridge. quantity defaults to 1
returns True if there is enough, false otherwise.
"""

return self.has_various({food_name:quantity})

def has_various(self, foods):
"""
has various(foods) determines if the dictionary food_name
has enough of every element to satisfy a request.
returns true if there's enough, Fasle if there's not or if an element does
not exist.
"""
try:
for food in foods.keys():
if self.items[food] < foods[food]:
return False
return True
except KeyError:
return False


.



Relevant Pages

  • Re: Question for established T2s
    ... > about DM, my body, my diet and understanding how certain foods and food ... > purposes but also to check new or occasionally troublesome foods. ... per day since that's part of the process of learning how to effectively ... control your condition through diet and exercise. ...
    (alt.support.diabetes)
  • Re: Muttleys long weekend adventures
    ... much of the wrong foods, and don't get enough exercise. ... Differences in hunger-control hormone production, differences in sleep patterns, differences in an emerging number of genetic factors that modulate hormones and behavior. ... And when a solid scientific explanation of these types of differences emerges, don't expect understanding and compassion on the part of the public to follow close on its heels. ...
    (rec.pets.dogs.behavior)
  • Re: Metformin and other diabetic drugs
    ... >>understanding, you may decide to change some of those ... >>Cheers, Alan, T2, Australia. ... >foods are bad for me, ...
    (alt.support.diabetes)
  • Re: Struggling with basics
    ... > def addScore: ... > My first problem is that if I run the ... I get an error saying: ... > Apologies for going over old ground and if I'm not understanding, ...
    (comp.lang.python)
  • Re: Question for established T2s
    ... || learning about DM, my body, my diet and understanding how ... || certain foods and food combinations affect my BG levels. ...
    (alt.support.diabetes)