[Tutor] bug hunting again

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 8 Jul 2002 12:37:35 -0700 (PDT)


On Mon, 8 Jul 2002, Kyle Babich wrote:

> Ok now my problem is this:
>
>   File "hourtracker.py", line 92, in ?
>     if username.lower() in "kyle jason chelsea john cheryl".split():
> AttributeError: 'string' object has no attribute 'lower'
>
> But I don't see what is wrong.

Hi Kyle,

Just to make sure: which version of Python are you running?  Can you check
to see if it is Python 1.52, or Python 2.2?  If it's 1.52, the reason
you're running into problems is because strings didn't have methods at
that time.


In 1.52, we'll get an error if we try using a string method:

###
[dyoo@tesuque dyoo]$ /usr/bin/python
Python 1.5.2 (#1, Apr  3 2002, 18:16:26)  [GCC 2.96 20000731 (Red Hat
Linux 7.2 2 on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> ''.lower()
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: 'string' object has no attribute 'lower'
###

and this looks like the error that you're running into.


If you're stuck using 1.52 and can't upgrade to a newer version, then you
may need to reword things.  The equivalent way of saying:

    if username.lower() in "kyle jason chelsea john cheryl".split():

in 1.52 style would be:

    if string.lower(username) in \
        string.split("kyle jason chelsea john cheryl")

(The line was getting long, so I use a "continuation" character '\' here
to tell Python that there's more stuff on the next line.)




Hope this helps!