[FRPythoneers] Question about Try/Except

J. Wayde Allen wallen at its.bldrdoc.gov
Mon Jun 3 15:34:32 MDT 2002

On Mon, 3 Jun 2002, Sean Reifschneider wrote:

> 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.

Yes, I don't feel comfortable with the "bare exception" idea.  Got that
construct from
<http://www.devshed.com/Server_Side/Python/CGI/page1.html>.  What you are
suggesting makes a lot more sense to me.

> string anyway, and possibly only white-spaces, but in the end you can't
> prevent somone from not putting in a last name...

True ... this raises another question I have with regards to form data
fields.  Testing the fields is always brought up in various books and web
pages as necessary to ensure security.  What I often wonder about is how
much is enough?  Taking care about how these data are used, how they are
passed to other system programs, etc. seems to make a lot of sense, but

- Wayde
  (wallen at its.bldrdoc.gov)

More information about the FRPythoneers mailing list