[Python-Dev] enum discussion: can someone please summarize open issues?
greg.ewing at canterbury.ac.nz
Sat May 4 08:46:35 CEST 2013
Guido van Rossum wrote:
> Code that wants to validate a string the user typed as input. Web
> forms just don't work that way.
Maybe "validation" was a misleading term to use. To be
more precise, I'm talking about taking input to the
program (it needn't come directly from a user, it could
be read from a file or database) that is supposed to
be the name of a Color, and turning it into a Color
For that purpose, it's convenient to have a function
with only two possible outcomes: it either returns a
Color instance, or raises a ValueError.
The point is that you *shouldn't* have to perform a
separate validation step. You should be able to use
EAFP -- go ahead and perform the conversion, but be
prepared to catch a ValueError at some level and
report it to the user.
More information about the Python-Dev