0

I've saved a .txt file of data points onto my desktop. I wrote my script in spyder as follows:

from pylab import *
data = genfromtxt('data.txt', skip_header = 5, skip_footer = 6)
print data

This returns an error code saying "data.txt not found" I've spent over 30 min trying to figure this out and I'm sure it's going to be a trivial fix. What am I missing?

  • 1
    Is data.txt in the same directory as your script for a relative search? Or maybe typing the absolute path would work instead of just data.txt, like `r'C:\users\\desktop\data.txt'`. – DragonautX Oct 28 '16 at 03:54
  • That worked! I had the txt in my desktop and the py file in a separate folder. I assumed the computer would just grab it from any directory. Thank you. – Hector Nevarez Oct 28 '16 at 04:12
  • Cool. I'll turn it into an answer then. – DragonautX Oct 28 '16 at 04:32

1 Answers1

0

With a "file not found" type of error, the error is likely based on a failed directory search, not with any specific modules like pylab. In your case, you can just add data.txt to the same directory as your script. This makes a relative search work. You can also specify the absolute path, like r'C:\users\<username>\desktop\data.txt'. Python does other things in a directory search, like looking at your PATH environment variable in Windows, but working with the relative and absolute paths are the easiest.

DragonautX
  • 860
  • 1
  • 12
  • 22