There is no such file or directory error

This is the error I get:

Traceback (most recent call last):
  File "E:\stuff\module.py", line 91, in <module>
    f = open('E:/stuff/log.txt')
IOError: [Errno 2] No such file or directory: 'E:/stuff/log.txt'

And this is my code:

f = open('E:/stuff/log.txt')

The file E:/stuff/log.txtexists. I can navigate in Windows Explorer and open it, so why not open it?

EDIT:

DIR command output:

C:\Documents and Settings\Administrator>dir e:\stuff
 Volume in drive E has no label.
 Volume Serial Number is 5660-4957

 Directory of e:\stuff

23. 10. 2010  09:26    <DIR>          .
23. 10. 2010  09:26    <DIR>          ..
19. 10. 2010  20:07               385 index.py
23. 10. 2010  16:12             1 954 module.py
22. 10. 2010  19:16             8 335 backprop.py
19. 10. 2010  20:54             1 307 backprop-input.gif
19. 10. 2010  01:48               310 HelloWorld.kpf
23. 10. 2010  15:47                 0 log.txt.txt
               6 File(s)         12 291 bytes
               2 Dir(s)   8 795 586 560 bytes free



C:\Documents and Settings\Administrator>dir e:\
 Volume in drive E has no label.
 Volume Serial Number is 5660-4957

 Directory of e:\

16. 10. 2010  13:32    <DIR>          development-tools
23. 10. 2010  09:26    <DIR>          stuff
               0 File(s)              0 bytes
               2 Dir(s)   8 795 586 560 bytes free

I am running a python script from cmd as follows:

python E:\stuff\module.py
+3
source share
6 answers

Firstly, the top is supported by Windows / simply.

Secondly: Well, if you look at your file, you will notice that it is not log.txt, it is log.txt.txt ... You can see it as "log.txt" in your graphical folder viewer (unlike from CLI) dir ") simply because it hides known file extensions.

- . , " " ( ).

+8

"dir":

23. 10. 2010  15:47                 0 log.txt.txt

, , "log.txt.txt", "log.txt". , , Windows, , . , . "" > " ", , .

+3

? , ( )

+1

, - escape-, , .

e:\\stuff\\log.txt
+1

, , , :

import os

file_name = os.path.join("e:\\stuff", "log.txt")

f = open(file_name)

:

f = open('E:/stuff/log.txt')

Windows / .

+1
source

Define path names using os.path.join()

root="E:\\"
mylog = os.path.join(root,"stuff","log.txt") # or log.txt.txt as seen in your dir output
f = open(mylog)
...
f.close()
+1
source

Source: https://habr.com/ru/post/1771072/


All Articles