What's wrong with me/Python ?
Don O'Donnell
donod at home.com
Tue Mar 13 22:20:37 EST 2001
Erik Max Francis wrote:
>
> Alexander Stirzel wrote:
>
> > I just wrote a small script for killing some hanging netscape
> > processes,
> > the source is listed below.
> > Now if I run this script I get this error message:
> >
> > 8<----------- error message -----------------------------
> > Traceback (most recent call last):
> > File "/usr/sbin/netscape-killer.py", line 11, in ?
> > splitted = string.split(line)
> > NameError: There is no variable named 'string'
> > 8<----------- error message -----------------------------
> >
> > Now here's the script:
> >
> > 8<------------ script -----------------------------------
> > #!/usr/local/bin/python
> > import os
> > import time
> ...
>
> > What did I do wrong? And why does Python want a "variable named
> > 'string'" here?
>
> Because you're referencing `string' and it's never seen the variable
> before. You're missing an `import string' statement at the top.
>
Or better yet, with version 2.0, use the string method:
splitted = line.split()
and you don't have to remember to import the string module.
It should be faster as well, since the string functions are
now implemented as calls to the string methods.
/Don
More information about the Python-list
mailing list