def safe_open(path, mode='w', chmod=None, buffering=None):
 open_args = (() if (chmod is None) else (chmod,))
 fdopen_args = (() if (buffering is None) else (buffering,))
 return os.fdopen(os.open(path, ((os.O_CREAT | os.O_EXCL) | os.O_RDWR), *open_args), mode, *fdopen_args)

def safe_open ( path , mode = 'w' , chmod = None , buffering = None ) : open_args = ( ( ) if ( chmod is None ) else ( chmod , ) ) fdopen_args = ( ( ) if ( buffering is None ) else ( buffering , ) ) return os . fdopen ( os . open ( path , ( ( os . O_CREAT | os . O_EXCL ) | os . O_RDWR ) , * open_args ) , mode , * fdopen_args )
safely open a file .