[Tutor] Is my style OK in this elementary student exercise?
Angus Rodgers
angusr at bigfoot.com
Sun Jul 5 01:30:57 CEST 2009
>Date: Sat, 4 Jul 2009 19:52:56 +0100
>From: "Alan Gauld" <alan.gauld at btinternet.com>
>Message-ID: <h2o8e5$h31$1 at ger.gmane.org>
>
>You can miss out a few else clauses, especially after
>the try/excepts:
>
>-----------
>while get_bool("Continue?"):
> try: key = eval(raw_input("Key value of type " + key_typ.__name__ + ": "))
> except StandardError: print "That's not a Python expression!"
>
> if not isinstance(key, key_typ):
> print "That's not a value of type", key_typ.__name__ else: # User has provided
> try: val = eval(raw_input("Object of type " + val_typ.__name__ + ": "))
> except StandardError: print "That's not a Python expression!"
>
> if not isinstance(val, val_typ):
> print "That's not an object of type", val_typ.__name__
> else: # User has provided an object of the correct type
> ans[key] = val
>return ans
>------------
I don't see this, because, if an exception does occur, won't
there be an attempt to access one of the objects 'key', 'val'
before it has been assigned?
Not that this matters in the largely rewritten "Version 0.1":
<http://python.pastebin.com/d7020f124> (retention: 1 day)
(Is it time for me to get into the comfy chair yet?) 8-P
--
Angus Rodgers
More information about the Tutor
mailing list