Skip to content

Instantly share code, notes, and snippets.

@romach
Created April 2, 2017 21:47
Show Gist options
  • Save romach/885015c2bfd169a89ad64f862300c1be to your computer and use it in GitHub Desktop.
Save romach/885015c2bfd169a89ad64f862300c1be to your computer and use it in GitHub Desktop.
Create file if not exists, throw exception in other case
def write_content_to_file(content, file_path):
output_file = os.fdopen(os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_EXCL), "w")
output_file.write(content)
output_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment