What's wrong with me/Python ?

Alexander Stirzel alexander.stirzel at daimlerchrysler.com
Tue Mar 13 12:36:50 CET 2001


Hi!

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

while 1:
  time.sleep(600)
  f = os.popen("ps aux")
  lines = f.read()
  f.close()
  for line in lines:
    splitted = string.split(line)
    if (string.find('netscape',splitted.pop()))-1:
      cputime = splitted.pop()
      cputime = string.replace(cputime, ":", " ")
      cputime = string.split(cputime)
      cputime.reverse
      cputime = cputime.pop()
      if (string.atoi(cputime)>15):
        splitted.reverse
        pid = splitted.pop()
        pid = splitted.pop()
        os.kill(pid,9)
8<------------ script -----------------------------------

What did I do wrong? And why does Python want a "variable named
'string'" here?

Thanks in advance

-- 
Alexander Stirzel 
E-Mail: alexander.stirzel at informatik.uni-ulm.de



More information about the Python-list mailing list