0
#!/usr/bin/python 
data = open("/home/mia/Desktop/results/all-nodup.txt", "r")
fd = open("/home/mia/Desktop/results/all-filter.txt", "w")

last_time = 0.0
last_ip = None
last_hash = None
row = data.read()

for line in row:
      timestamp, ip, hash_value = line.split()

      if ip==last_ip and hash_value==last_hash:  

           if float(timestamp) - float(last_time) >= 5.0:
             fd.write("%s\t%s\t%s\n" % (str(timestamp), str(ip), str(hash_value))) 
             last_time, last_ip, last_hash = timestamp, ip, hash_value
      else:
           fd.write("%s\t%s\t%s\n" % (str(timestamp), str(ip), str(hash_value)))   
           last_time, last_ip, last_hash = timestamp, ip, hash_value

fd.close()

This is my entire code, I go to results/ directory to run: python filter.py I got an error message: python: can't open file 'filter.py': [Errno 2] No such file or directory

But every other scripts can be executed, so python works fine, maybe I should import something in this case?

1
  • 2
    Without changing directory, what does ls filter.py show? How about head -1 filter.py ? Commented Dec 1, 2011 at 16:39

2 Answers 2

1

python can't even find your filter.py script file, so changing your code is useless. To fix that you'll either need to:

  • put filter.py inside results/ directory
  • use absolute path, e.g. python /path/to/script/filter.py
  • figure out the correct relative path, e.g. python ../../blah/filter.py
  • put the path where filter.py resides into your PATH variable
Sign up to request clarification or add additional context in comments.

Comments

0

That's because filter.py is not in the directory you're running the command in.

Try python /path/to/filter.py. You can also use relative paths, for example, if the file is one directory up, use python ../filter.py.

4 Comments

@Lie Ryan I am 1000000% sure it is in the same directory
@ShawnChin yes, pretty sure, that's why it's so strange
@manxing: the error message says there isn't a file named filter.py in the current directory; since you're changing directory, the script file is no longer in your current directory
filter.py is in /home/mia/Desktop/results, and that's also where you run the command? (don't mean to be condescending, but this is really strange and we need to properly rule this out before hunting for other possibilities)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.