0% found this document useful (0 votes)
17 views1 page

Python

The document is a Python script that creates a directory named 'sod' and a text file named 'example.txt' within it. It ensures the directory exists before writing a sample text to the file. Finally, it prints the path of the created file.

Uploaded by

gitwitayeho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Python

The document is a Python script that creates a directory named 'sod' and a text file named 'example.txt' within it. It ensures the directory exists before writing a sample text to the file. Finally, it prints the path of the created file.

Uploaded by

gitwitayeho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import os

# Define directory and file path


directory = "sod"
file_path = os.path.join(directory, "example.txt")

# Ensure the directory exists


os.makedirs(directory, exist_ok=True)

# Create and write to the file


with open(file_path, "w") as file:
file.write("This is an example text file.")

print(f"File created at: {file_path}")

You might also like