[FRPythoneers] Question about Try/Except

Sean Reifschneider jafo at tummy.com
Mon Jun 3 15:08:18 MDT 2002

On Mon, Jun 03, 2002 at 03:16:04PM -0600, J. Wayde Allen wrote:
>   try:
>      surname = form["last_name"].value
>   except:
>      Display("You must supply a first and last name.  Please go back.")
>      raise SystemExit

Using "bare exception" is considered bad form because it masks other
errors.  You probably wanted to do:

   surname = form.get('last_name'):
   if not surname or not string.strip(surname):

dictionary.get('key') doesn't raise an exception if that key doesn't exist,
it returns "None".  "if not string" fails if the string is None *OR* if
it's an empty string.

In this case, I don't know why you are getting an empty string when you
moved it to another machine.  You should probably be checking for the empty
string anyway, and possibly only white-spaces, but in the end you can't
prevent somone from not putting in a last name...

 The blood of the guitar was Chuck Berry Red.
                 -- Meatloaf
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python

More information about the FRPythoneers mailing list