[Tutor] guess the error cause time!
Daniel Yoo
dyoo@CSUA.Berkeley.EDU
Sat, 21 Sep 2002 21:51:23 -0700 (PDT)
On Sun, 22 Sep 2002, Kirk Bailey wrote:
> OK, here is the error:
>
> File "/www/www.tinylist.org/cgi-bin/TLcommander.py", line 155, in bullshit
> if data not in
> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_":
> TypeError: string member test needs char left operand
What it's saying is that 'data' itself is not a single character. It's a
good thing that it's saying that because it's pointing out a bug in the
code:
###
def bull(data):
for i in data:
if data not in ("abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"):
## [rest of body cut]
###
In particular, the variable 'i' is not being used anywhere in this loop,
but I think you really do mean to use it... somewhere... *grin*
A regular-expression approach to your problem might be to use a "negative"
character class:
###
def bull(data):
good_chars = ("abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_")
evil_pattern = re.compile('[^%s]' % good_chars)
if evil_pattern.search(data):
pass # ... we've detected evil characters in the string.
###
Good luck!