Re: [Tutor] Newbie Question on Exceptions...

2007-05-08 Thread John Fouhy
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?

Re: [Tutor] Newbie Question on Exceptions...

2007-05-08 Thread Alan Gauld
<[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): >

Re: [Tutor] Newbie Question on Exceptions...

2007-05-08 Thread Andre Engels
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

Re: [Tutor] Newbie Question on Exceptions...

2007-05-08 Thread Bob Gailer
[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_

[Tutor] Newbie Question on Exceptions...

2007-05-08 Thread dsh0105
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