File Open Function with Try & Except Python 2.7.1

后端 未结 4 933
不知归路
不知归路 2020-12-07 02:46
def FileCheck(fn):       
       try:
           fn=open(\"TestFile.txt\",\"U\") 
       except IOError: 
           print \"Error: File does not appear to exist.\"
         


        
4条回答
  •  隐瞒了意图╮
    2020-12-07 03:17

    This is likely because you want to open the file in read mode. Replace the "U" with "r".

    Of course, you can use os.path.isfile('filepath') too.

提交回复
热议问题