Skip to content

Instantly share code, notes, and snippets.

@pFransozi
Created July 13, 2023 01:08
Show Gist options
  • Save pFransozi/2d480a3c3d48ce0ad3f4b902d6b818d4 to your computer and use it in GitHub Desktop.
Save pFransozi/2d480a3c3d48ce0ad3f4b902d6b818d4 to your computer and use it in GitHub Desktop.
py create new dir and file
import os
if not os.path.exists("new_dir"):
os.makedirs("new_dir")
file = os.path.join("new_dir", "new_file.txt")
with open(file, "w") as f:
f.write("Hello, world")
with open(file, "r") as f:
print(f.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment