Created
October 26, 2020 11:45
-
-
Save pandorica-opens/4d903e8cfc5677ff9cf8f71b3b7cab64 to your computer and use it in GitHub Desktop.
The create_python_script function creates a new python script in the current working directory, adds the line of comments to it declared by the 'comments' variable, and returns the size of the new 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 | |
| def create_python_script(filename): | |
| comments = "# Start of a new Python program" | |
| with open(filename, 'a+') as f: | |
| f.write(comments) | |
| print(f.read()) | |
| filesize = os.path.getsize(filename) | |
| return(filesize) | |
| print(create_python_script("program.py")) |
Mazdak2023
commented
Mar 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment