Skip to content

Instantly share code, notes, and snippets.

@pbeens
Created January 12, 2024 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbeens/602faed79089b85e8a808626aaaeb256 to your computer and use it in GitHub Desktop.
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__).
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