diff options
author | Christian Cleberg <hello@cleberg.net> | 2025-05-20 14:37:37 -0500 |
---|---|---|
committer | Christian Cleberg <hello@cleberg.net> | 2025-05-20 14:37:37 -0500 |
commit | 3fed2f0b637ca18343fb0082e44532d470c1b61f (patch) | |
tree | ff2067f2359b660776b603632cb11766551e9dd5 | |
parent | 0828f6d7fbf59165980e17d126b1c4730c0a3ee0 (diff) | |
download | learn-3fed2f0b637ca18343fb0082e44532d470c1b61f.tar.gz learn-3fed2f0b637ca18343fb0082e44532d470c1b61f.tar.bz2 learn-3fed2f0b637ca18343fb0082e44532d470c1b61f.zip |
feat: add 'cat' script in Python
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python/cat.py | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c17ac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +python/venv
\ No newline at end of file diff --git a/python/cat.py b/python/cat.py new file mode 100644 index 0000000..d93ba65 --- /dev/null +++ b/python/cat.py @@ -0,0 +1,13 @@ +import argparse + +# Create an argument parser to obtain file name +parser = argparse.ArgumentParser(description='cat') +parser.add_argument('-f', '--file', help='File name') +args = parser.parse_args() + +# Open the file using the `file` argument +path = args.file +with open(path, 'r') as file: + # Read and print the file contents + contents = file.read() + print(contents) |