Short snippet to create a new file in a new directory tree in Python.
filename = "/foo/bar/baz.txt"
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
with open(filename, "w") as f:
f.write("FOOBAR")
Brak komentarzy:
Prześlij komentarz