pythonwindowsfilenetwork-share

Can't open a .txt file


So I was trying to learn the function open which is apparently easy to use. I copied a really simple code from a website to just open and read a file called "test.txt" with some text on it. I tried it both ways, not specifying the path (since it's in the same folder) and calling the whole path. None worked (FileNotFoundError). It's all in a server so that might be the problem but I'd still like a short explanation if that is the problem. Go easy on the vocabulary please, I'm just taking the first steps.

On the image I tried to stack as much info as posible: link.

handle = open("test.txt")
data = handle.read()
print(data)
handle.close()

SOLUTION: I actually just removed the .txt from the text file. Now it's name is test and it is a text file and the code works. I previously moved the python file and text file from the server to the computer since a comment said it could be the problem, but after finding my solution i put it all back in the server and the program runs as well.


Solution

  • You are trying to open a file that is located on a network share (\\Servidor\profiles$\...) and you are accessing it by using the \\<server>\<sharename> syntax and not mounted as a Windows drive letter.

    Some things you could try:

    1. Copy the data from the network share to some local directory on your machine and run your script again.
    2. Try mounting the network share under a "drive letter" and run again using this drive letter.
    3. Try this answer: https://stackoverflow.com/a/7170008/8745384 if you really need to access it on the network share.