On 09/05/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> try:
> print "The fridge contains %s" %fridge[food_sought]
> except (KeyError):
> print "The fridge does not contain %s"%food_sought
[...]
> Is the same true of Python? Or is ok to use Exception handling like the book
> suggests?
<[EMAIL PROTECTED]> wrote
> fridge={"apple":"A shiny red apple","pear":"a nice ripe
> pear","grapes":"seadless grapes"}
> food_sought="apple"
> fridge_list=fridge.keys();
Not sure what this line is for...
> try:
>print "The fridge contains %s" %fridge[food_sought]
> except (KeyError):
>
2007/5/8, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> I'm working my way through the book "beginning python" and I came across an
> exercise that suggests using Exception trapping to see if a value is in a
> dictionary:
>
> fridge={"apple":"A shiny red apple","pear":"a nice ripe
> pear","grapes":"s
[EMAIL PROTECTED] wrote:
> I'm working my way through the book "beginning python" and I came across an
> exercise that suggests using Exception trapping to see if a value is in a
> dictionary:
>
> fridge={"apple":"A shiny red apple","pear":"a nice ripe
> pear","grapes":"seadless grapes"}
> food_
I'm working my way through the book "beginning python" and I came across an
exercise that suggests using Exception trapping to see if a value is in a
dictionary:
fridge={"apple":"A shiny red apple","pear":"a nice ripe
pear","grapes":"seadless grapes"}
food_sought="apple"
fridge_list=fridge.keys