I need help with an indexing error i appreciate any input

I think the file path isn’t loading into the array at all because when i len(filenames) it returns 0 and i don’t know why the code runs on mac but wont work on windows for some reason.
I’m not the best coder. hopefully the picture went through, I had to black out some info for file paths.

I think the problem is with how you wrote the path.

The path is in a string literal and it contains \r, which is being interpreted as a carriage return and not as a backslash followed by the letter ‘r’.

Either it write as a raw string literal r'D:\...\rawdata' or with slashes instead of backslashes 'D:/.../rawdata'.

Thank you so much I can’t believe I forgot you have to \ in windows.



General debugging hints:

  • Did you try to check that path gets the expected value, after making the format call?
  • How about the path+'*' result; does that look like what you want? (Is rawdata a folder whose contents you want to use? Or is it the prefix of the file names you’re interested in?)
  • How about the glob.glob result? The problem seems to be that the filenames list doesn’t get populated, right? So, work backwards. It’s supposed to get populated by the loop running, right? Then, there are two things that can go wrong: either the loop doesn’t run, or the code inside the loop does the wrong thing. You get the idea.

In your case, you will find that the glob.glob result is empty, which then leads to testing simpler options - an os.listdir result, or a directly specified single filename - which reveals the problem.

Of course, it’s also necessary to check if “the lights are on” - people on the Internet don’t (thankfully) have access to your file system, so they don’t have any way to make sure that you actually have the necessary files in the appropriate places.

  • When something “runs on Mac but won’t work on Windows”, or anything else like that, that should be the basis for any searching you do to look for information. In this case, it’s pretty obvious that you had to change the code that sets path, since something starting with D:\ doesn’t make any sense for a Mac path. If it occurs to you that you consciously changed a line of code to specify a path, and that the problem is Windows specific, that should give you all the necessary tools to start searching to figure out what’s involved in specifying a path on Windows. Whether you phrase that as a how-to question or a debugging question, the necessary information should be reasonably easy to find. (It might involve working past questions about finding Python itself, or other such irrelevancies.)