check for file existence in Python 3 [duplicate]

if the file is not a file :(return False)

import os.path
if not os.path.isFile(file_name):
      print("The File s% it's not created "%file_name)
      os.touch(file_name)
      print("The file s% has been Created ..."%file_name)

And you can write a simple code based on (try,Except):

try:
    my_file = open(file_name)
except IOError:
    os.touch(file_name)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)