1
1
Fork 0

add files
Some checks failed
Lint Code / Ruff (push) Successful in 9s
Lint Code / MyPy (push) Failing after 11s
Lint Code / Pylint (push) Failing after 10s

This commit is contained in:
Seaswimmer 2024-06-05 23:55:53 -04:00
parent c04142c2bd
commit 5d84a1ff65
Signed by: cswimr
GPG key ID: 5D671B5D03D65A7F
3 changed files with 12 additions and 1 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
__pycache__ __pycache__
files/test.txt

0
files/__init__.py Normal file
View file

10
files/main.py Normal file
View file

@ -0,0 +1,10 @@
if __name__ == '__main__': # prevent this code from running whenever this file is imported in another file as a module
file_path = "test.txt" # we will be opening this file
try: # catch any exceptions that are thrown in the following block
with open(file_path, 'w') as f: # open the file (this is a context manager, so it automatically handles closing the file descriptor once we're done with it)
f.write('Hello, World!\n') # write to the file
except Exception as e: # if an exception is raised, catch it and process it
if isinstance(e, PermissionError): # if the exception being caught is a PermissionsError, execute the following code
print(f'Cannot write to file {file_path}, permission denied')
else: # if not, execute the following code
print(f'Cannot write to file {file_path}\n{e}')