0

I'm going nuts as I've done a lot of searching. Here is the Python code:

import os
def checknum(datafile):
    lrow = []
    mess="All OK."
    with open(datafile, "rb") as f:

. . .

DATADIR = "c:\data"

DATAFILE = "Wind Turbine Power Data_Test_GEInternal.csv"
datafile=os.path.join(DATADIR,DATAFILE)

mess=checknum(datafile)

I'm using the whole path. What am I missing?

Thanks, Larry

Larry Field
  • 63
  • 1
  • 2
  • 8

1 Answers1

4

You are missing an extra backslash in the data dir name:

DATADIR = "c:\\data"

Backslashes need to be escaped in string constants. Alternatively, you can use a / instead, with no problems in python:

DATADIR = "c:/data"

or

DATADIR = r"c:\data"
JuniorCompressor
  • 19,631
  • 4
  • 30
  • 57
  • 1
    you can also use a raw string literal: `r"c:\data"` – MattDMo Mar 15 '15 at 16:38
  • You're right, I didn't provide the full message. Here it is: IOError: [Errno 2] No such file or directory: 'c:\\data\\Wind Turbine Power Data_Test_GEInternal.csv' Note the \\. None of the proposed solutions worked. I probably also need to note that this is a Windows 64 Bit system - Windows 7. I had not researched the os package. So, I'll do that. Are you saying that os will treat text as RE? I'm very new to Python. The course I just took just implemented code in a similar problem like I did, so I'm a little buffaloed. – Larry Field Mar 16 '15 at 23:23
  • Can you check your c:\data directory for the exact name of your csv? I suspect there is a a typo. – JuniorCompressor Mar 16 '15 at 23:29
  • Yes, upper case "C" also does not work. I intentionally did a C/P of the file name so that I wouldn't make a typo. I checked anyway (a few times, since this just shouldn't be happening). Sorry, it's spelled right. – Larry Field Mar 16 '15 at 23:37
  • Now, here's the other wrinkle. Being Windows, it has a bizarre directory system. The path can also be D:\Users\MyUID\data. Is that a cause for concern? Actually, when I use that path, Python mangles my UID. I don't want to explore a new problem. – Larry Field Mar 16 '15 at 23:38
  • Try then DATADIR="D:\\Users\\MyUID\\data" – JuniorCompressor Mar 16 '15 at 23:41
  • Well, rats! I just found the typo! A missing space. Thanks for your help. On to the next adventure. – Larry Field Mar 17 '15 at 00:02