#!/usr/bin/env python # Try to create a file with the given file name, but throws an exception # if a file with that name already exists. import os import sys filename = sys.argv[1] try: fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0666) except OSError, (errno, strerror): print 'error(%s): %s' % (errno, strerror)