Create a file if it doesn’t exist

If you don’t need atomicity you can use os module: UPDATE: As Cory Klein mentioned, on Mac OS for using os.mknod() you need a root permissions, so if you are Mac OS user, you may use open() instead of os.mknod()