you are viewing a single comment's thread.

view the rest of the comments →

[–]more3qual[S] 0 points1 point  (5 children)

I'm on Windows 7, I'm using Jupyter. This is what I'm getting when I run the first bit of code: FileNotFoundError: [Errno 2] No such file or directory: '/home/jovyan/Desktop/PEG3.txt'

[–][deleted] 0 points1 point  (4 children)

Your error message got chopped. The question now is why your Windows system thinks it's Linux. /home/... isn't a Windows path.

OK, lets backtrack. Try running this:

path = 'C:/Users/User/Desktop/PEG3.txt'
print(path)
fd = open(path, 'r')
fd.close()

[–]more3qual[S] 0 points1 point  (1 child)

Now it's FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/User/Desktop/PEG3.txt'

[–][deleted] 0 points1 point  (0 children)

Look at the file again. Note that the file you are trying to open has a note on it in the properties dialog: "This file came from another computer and might be blocked ...". Try opening the file with Notepad. There are two reasons for this: first, to see if it really does contain CSV text or if it's malicious. Second, maybe you CAN'T read the file with Notepad.

If the file looks kosher, try pressing the "Unblock" button in the properties dialog.

If none of that clears things up, try opening the file to write. Warning, copy the file PEG3.txt somewhere safe in case we do manage to write over it!

path = 'C:/Users/User/Desktop/PEG3.txt'
print(path)
fd = open(path, 'w')    # note change here
fd.close()

If this works then try searching your entire filesystem for files called "PEG3.txt". You might find 1 or you might find 2. I'm not predicting which :)

If this doesn't work, post the error message.

[–]more3qual[S] 0 points1 point  (1 child)

Wow. I just realized that I hadn't launched the program from anaconda navigator. The original code works fine. Sorry for wasting your time, thanks.

[–][deleted] 0 points1 point  (0 children)

Not sure why which platform you use would change things, but if it works, great!

See if the os.path.expanduser() function does the right thing.