Python IOError: File not open for reading

前端 未结 2 1398
[愿得一人]
[愿得一人] 2021-02-07 01:24

I get an error when I try to open a file in Python. Here is my code :

>>> import os.path
>>> os.path.isfile(\'/path/to/file/t1.txt\')
>>&         


        
2条回答
  •  别那么骄傲
    2021-02-07 02:18

    Simple mistake if you think about it it. In your code you are doing:

    myfile = open('/path/to/file/t1.txt','w')
    

    Which specifies it is for writing, what you need to do is set this to r which is for read

    myfile = open('/path/to/file/t1.txt','r')
    

提交回复
热议问题