Say I want to make a file:
filename = "/foo/bar/baz.txt"
with open(filename, "w") as f:
f.write("FOOBAR")
This gives an IOError, since /foo/bar does not exist.
What is the most pythonic way to generate those directories automatically? Is it necessary for me explicitly call os.path.exists and os.mkdir on every single one (i.e., /foo, then /foo/bar)?