Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # writes file to filepath, creates dir if does not exist
- from pathlib import Path
- path = Path("/your/file/path/name_of_dir") # path of dir
- path.mkdir(parents=True, exist_ok=True) # cretes dir if not exist
- file = "name_of_file.txt" # file name
- filepath = path / file # joins path and file
- with open(filepath, "w") as f:
- f.write("This is an example file")
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment