You can use the os module:
Like this: os.path.isfile ():
import os.path os.path.isfile(file_path)
Or using os.path.exists ():
if os.path.exists(file_name)==True: print("I get the file >hubaa")
if the file does not exist: (return False)
if os.path.exists(file_name)==False: print("The File s% it not created "%file_name) os.touch(file_name) print("The file s% has been Created ..."%file_name)
And you can write simple code based on (try, Except):
try: my_file = open(file_name) except IOError: os.touch(file_name)
source share