Created
January 12, 2024 15:36
-
-
Save pbeens/602faed79089b85e8a808626aaaeb256 to your computer and use it in GitHub Desktop.
This Python script saves a file with the specified filename to the current working directory using the os module. The current working directory is determined by calling os.path.dirname(__file__).
This file contains 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 | |
# Get the current working directory | |
current_dir = os.path.dirname(__file__) | |
# Create a file path that includes the current working directory | |
file_path = os.path.join(current_dir, "filename.txt") | |
# Save the file with the file path | |
with open(file_path, "w") as file: | |
file.write("Hello, world!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment