scanning for numerals / letters
johnzenger at gmail.com
johnzenger at gmail.com
Wed Apr 19 03:52:33 EDT 2006
First, note that form["date"] is all you need. form["date"].value is
redundant.
I would do this with sets:
import string
if set(form["date"]) & set(string.ascii_letters) != set([]): print "You
have to enter a date with numbers"
if set(form["purchases"]) & set(string.digits) != set([]): print
"Please do not use numbers"
Sets take time to construct, but they test membership faster than
strings. Plus, the code just reads logically. (The &, if you couldn't
figure it out, does an intersection of sets. You could also use the
.intersection method for even better readability).
More information about the Python-list
mailing list