summaryrefslogtreecommitdiff
path: root/py04/ex0/ft_ancient_text.py
diff options
context:
space:
mode:
authoryctct <yctct@yctct.com>2026-06-07 08:59:04 +0200
committeryctct <yctct@yctct.com>2026-06-07 08:59:04 +0200
commit15115b4c52bfda0d1cca9fa1155beecbb873ec35 (patch)
treeb3f0975e63eb04dcba732a78ce9bd9abda8acf01 /py04/ex0/ft_ancient_text.py
First commit, add all files
Diffstat (limited to 'py04/ex0/ft_ancient_text.py')
-rwxr-xr-xpy04/ex0/ft_ancient_text.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/py04/ex0/ft_ancient_text.py b/py04/ex0/ft_ancient_text.py
new file mode 100755
index 0000000..152c0a2
--- /dev/null
+++ b/py04/ex0/ft_ancient_text.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def read_content() -> None:
+ file = None
+ try:
+ file = open(sys.argv[1])
+ content = file.read()
+ print(f"Accessing file {sys.argv[1]}")
+ print("---")
+ print()
+ print(content)
+ except IndexError:
+ print("Usage: ft_ancient_text.py <file>")
+ except FileNotFoundError as e:
+ print(f"Error opening the file '{sys.argv[1]}':", e)
+ # trying to write when disk is full
+ # also catch permission errors
+ except OSError as e:
+ print(e)
+ # No permission to read or write
+ except PermissionError as e:
+ print(e)
+ # file encoded in a format other than UTF-8
+ except UnicodeDecodeError as e:
+ print(e)
+ except IsADirectoryError as e:
+ print(e)
+ finally:
+ if file:
+ file.close()
+ print("---")
+ print(f"File '{sys.argv[1]}' closed.")
+
+
+def main() -> None:
+ print("=== Cyber Archives Recovery ===")
+ read_content()
+
+
+if __name__ == "__main__":
+ main()