If the file is for opening you could use one of the following techniques:
with open('somefile', 'xt') as f: #Using the x-flag, Python3.3 and above f.write('Hello\n')if not os.path.exists('somefile'): with open('somefile', 'wt') as f: f.write("Hello\n")else: print('File already exists!')
UPDATE
Just to avoid confusion and based on the answers I got, current answer finds either a file or a directory with the given name.