Python open() gives FileNotFoundError/IOError: Errno 2 No such file or directory

前端 未结 5 1294
孤街浪徒
孤街浪徒 2020-11-22 06:24

For some reason my code is having trouble opening a simple file:

This is the code:

file1 = open(\'recentlyUpdated.yaml\')

And the erro

5条回答
  •  情深已故
    2020-11-22 07:08

    Possibly, you closed the 'file1'.
    Just use 'w' flag, that create new file:

    file1 = open('recentlyUpdated.yaml', 'w')
    

    mode is an optional string that specifies the mode in which the file is opened. It defaults to 'r' which means open for reading in text mode. Other common values are 'w' for writing (truncating the file if it already exists)...

    (see also https://docs.python.org/3/library/functions.html?highlight=open#open)

提交回复
热议问题