0

I am writing a loop to plot data using matplotlib. to start, I have

path = os.listdir('/users/me/path_to_folder_with_data')
for file in path:
    code that I know works for plotting data

But when I run this, I get an error that says [Errno 2] No such file or directory: 'data1.txt' Is it trying to run from the folder that the program is saved in? This seemed to be the solution in similar questions here, but if thats true, why isn't it running from my path?

kylieCatt
  • 10,672
  • 5
  • 43
  • 51
GlassSeaHorse
  • 429
  • 2
  • 7
  • 14
  • 1
    People are so fast to downvote on this site.... The OP posted a small snippet of relevant code and the error that arises. Not sure how much more clean-cut a question can get. – Cory Kramer Nov 12 '14 at 21:16
  • I didn't downvote, but it's the `code that I know works for plotting data` that gives the error. – Matthias Nov 12 '14 at 21:40
  • @Cyber This question does not include a) the code that _actually_ raises the error b) the full back trace. It isn't hard to guess what the problem is, but that doesn't make this a good question. – tacaswell Nov 13 '14 at 15:22

1 Answers1

2

You need to join the path to the directory

location = '/users/me/path_to_folder_with_data'
for file in os.listdir(location):
    fullPath = os.path.join(location, file)
    # now try to open fullPath
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218