Need help with string method

Donn Cave donn at u.washington.edu
Fri Dec 29 12:37:27 EST 2000


Quoth jvanar1 at my-deja.com:
| I have a pretty dumb question here.  I can't seem to get any string
| methods working from *within* a script.  here is a super-simple example
| that yields an error
|
| >>import sys
| >>import string
| >>theString = 'This is a string'
| >>print theString.find('string')
|
| now this works fine from the python command line but gives an error
| when run as a script. Here is the error message:
|
| Traceback (innermost last):
|   File "./clean", line 18, in ?
|     print theString.find('string')
| AttributeError: 'string' object has no attribute 'find'
|
| Am I missing an 'import' somewhere.  Thanks for any help...

   $ python -c 's = "hi"; print s.find("i")'
   1
   $ python1.5 -c 's = "hi"; print s.find("i")'
   Traceback (innermost last):
     File "<string>", line 1, in ?
   AttributeError: 'string' object has no attribute 'find'
   $

According to my theory, you're getting two interpreters, 2.0 when
you simply invoke python and version 1.5 when you run a file.

I don't know why.  If you invoke your file directly, then the
interpreter specified in the #! top line is probably not the
first python found in your PATH list.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list