H.Aziz Kayıhan
H.Aziz Kayıhan

Reputation: 325

New path is not reflected in Python code

I have a code in which I am loading a text file from a folder. The code looks like this:

snap1 = np.loadtxt("../data/milli_17")
snap2 = np.loadtxt("../data/milli_19")

So the milli17 and milli19 files are located in a folder that is located in the same folder with my working folder. So far everything was good. However, I moved the data folder inside the working directory so the directory placement became like this: /Workingdirectory/data/

So I went ahead and reflected that on the code by removing the two dots so it wouldn't go up one directory:

snap1 = np.loadtxt("/data/milli_17")
snap2 = np.loadtxt("/data/milli_19")

However now when I run the code I get an error saying the directory does not exist:

IOError: [Errno 2] No such file or directory: '../data/milli_17'

but debugging shows the line of error as this:

----> 4 snap1 = np.loadtxt("/data/milli_17")

Couldn't get my head around it, all seemed OK to me. Where do I make the mistake?

Edit: I don't think the problem has something to do with how I write down the path. The problem is that it doesn't matter what I put there, the code still (as seen in the error code) goes and checks the old directory.

Upvotes: 0

Views: 77

Answers (2)

user5806759
user5806759

Reputation:

If you restart the kernel that should resolve your issue.

Upvotes: 1

KnowNothing
KnowNothing

Reputation: 73

I believe you have to use the file extension and no forward slash before the data folder.

snap1 = np.loadtxt("data/milli_17.txt")

Upvotes: 0

Related Questions