[Tutor] Code/Style Review of Data Validation Code

Sean 'Shaleh' Perry shaleh at speakeasy.net
Tue Feb 24 22:33:40 EST 2004


On Tuesday 24 February 2004 15:41, Sean Abrahams wrote:
> The following is some code I wrote to validate certain types of data
> that is passed into a python script via a web form. However, the way it
> is implemented now you can pass in any set of rules and any set of data
> and get back some results on wether the data passed the tests.
>
> The style of the resulting dict helps with redisplaying the results
> back onto the web page.
>
> I'm interested in improving the code overall and perhaps working
> exceptions in, instead of using a specific dict format. Anyone have any
> arguments for creating a class for this type of stuff? etc?
>

Sorry, don't have time to comment on all of it.

However, I do have a question.  Why loop over the rules?  I would have done:

for key in data:
    if there is a rule and it is required:
      apply rule

This way, if I only get two pieces of data I can get right in and out.




More information about the Tutor mailing list