No such file or directory error

后端 未结 6 1673
有刺的猬
有刺的猬 2021-01-13 13:20

This is the error I am getting:

Traceback (most recent call last):
  File \"E:\\stuff\\module.py\", line 91, in 
    f = open(\'E:/stuff/log.tx         


        
相关标签:
6条回答
  • 2021-01-13 13:41

    Define you 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()
    
    0 讨论(0)
  • 2021-01-13 13:45

    it been a long time that i didn't use windows, but if i remember well windows use back-slash in system path so you should do:

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

    and not:

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

    there is not / in paths in windows.

    0 讨论(0)
  • 2021-01-13 13:50

    Firstly, from above, Windows supports / just fine.

    Secondly: Well, if you look at your file, you'll notice it's not log.txt, it's log.txt.txt... You may see it as "log.txt" in your graphical folder viewer (as opposed to the CLI "dir" command) simply because it hides the known file extensions.

    I recommend you disable this - see folder options, there should be an option "Hide extensions of known file types" (or similar).

    0 讨论(0)
  • 2021-01-13 13:58

    Since it is windows, and the backslash is a escape character, you must double the backslash to escape it. Try

    e:\\stuff\\log.txt
    
    0 讨论(0)
  • 2021-01-13 14:02

    Look at this line in the "dir" output:

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

    The file you are looking for is named "log.txt.txt", not "log.txt". I see this happen when people set up the Windows file manager to not show known file extensions and then they try to add or modify an extension. I recommend to others that they turn this behavior off. You can do this under View->Folder Options I believe.

    0 讨论(0)
  • 2021-01-13 14:05

    how about reading permissions? maybe not authorized to read (default mode of open)

    0 讨论(0)
提交回复
热议问题