Debian Codegraph @

examples/utilities.py

raw
1 import os
2 import sys
3
4
5 def ensure_no_files_overwritten(expected_contents):
6 # ensure we don't overwrite the user's files, if they run it on their machine
7 if os.path.exists("example.json"):
8 with open("example.json", "r") as f:
9 contents = f.read()
10 if contents != expected_contents:
11 # exit with a non-zero error code
12 sys.exit(
13 "I don't want to overwrite the example.json file in my current directory! Please delete example.txt and try again!"
14 )