[Tutor] unexpected error

Patrick K. O'Brien pobrien@orbtech.com
Tue, 9 Oct 2001 13:29:26 -0500


I'm biased, of course, but I think these kinds of situations are much easier
to understand and investigate in the PyCrust shell. All objects in the
current namespace can be drilled through in the PyCrust namespace tree
control (called PyFilling). If the object is a module, class or method,
PyFilling even displays the source code for the object. I've spent the past
couple of days poking around Zope and ZODB using PyCrust and it has been a
great learning experience. Just a suggestion.

http://sourceforge.net/projects/pycrust/

---
Patrick K. O'Brien
Orbtech (http://www.orbtech.com)
"I am, therefore I think."

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Danny Yoo
Sent: Tuesday, October 09, 2001 1:07 PM
To: Jerry Lake
Cc: tutor@python.org
Subject: Re: [Tutor] unexpected error

On Tue, 9 Oct 2001, Jerry Lake wrote:

> I'm reading through the eBook
> "how to think like a computer programmer" python version
> and I'm following along in chapter 7.9 "The string Module"
>
> however I get this error from this code, any ideas ? the output is
> completely not expected
>
> <snip>
> #!/usr/bin/python2
>
> import string
>
> fruit = "banana"
> count = 0
> index = 0
> for char in fruit:
>   if char == 'a':
>     count = count + 1
> print count
>
> indeX = string.find(fruit, "a")
> print indeX
> </snip>
>
> <output>
> this is a
> 14
> 1
> 3
> Traceback (most recent call last):
>   File "./fortest.py", line 13, in ?
>     indeX = string.find(fruit, "a")
> AttributeError: 'string' module has no attribute 'find'


??!  Weird!  Let's check one thing.  Can you put:

###
print string.__file__
###

right after you import the string module?  This will show us where Python
is finding the string module.

My best guess so far is that you might have a 'string.py' file in your
current directory, which is obscuring the standard library's string
module.  Here's what happens on my side when I run your snippet:

###
3
1
###


Hope this helps!


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor