How do I using with open() as f: ... to write the file in a directory that doesn\'t exist.
with open() as f: ...
For example:
For Python 3 can use with pathlib.Path:
from pathlib import Path p = Path('Users' / 'bill' / 'output') p.mkdir(exist_ok=True) (p / 'output-text.txt').open('w').write(...)