14 lines
307 B
Python
14 lines
307 B
Python
import os
|
|
|
|
def write_if_changed(path, content):
|
|
try:
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
if f.read() == content:
|
|
return
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(content)
|