Created
July 13, 2023 01:08
-
-
Save pFransozi/2d480a3c3d48ce0ad3f4b902d6b818d4 to your computer and use it in GitHub Desktop.
py create new dir and file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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