Skip to content

Conversation

@aydaeslami
Copy link

@aydaeslami aydaeslami commented Dec 1, 2025

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

This PR includes my solutions to simulate several shell tools in Python.
I used the argparse module to re-implement them.

@aydaeslami aydaeslami added 📅 Sprint 4 Assigned during Sprint 4 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 1, 2025
Copy link

@DaryaShirokova DaryaShirokova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress on this! Left a few comments here

description="Simple cat clone with -n and -b options",
)

counterNumber = 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python the usual code style is to use snake_case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. I’ll update the variable.

print(counterNumber, arrText[i])
counterNumber += 1
else:
print(content) No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please wrap you logic into a method and run it using if __name__ == "__main__": approach? Ideally the program should not contain global vars, and having methods improves readability.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I’ve moved the logic into functions, added a main() entry point using if name == "main": and removed global variables to improve readability.

)

counterNumber = 1
parser.add_argument("-n", action="store_true", help="number all lines")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cat -n sample-files/1.txt, cat.py sample-files/ *.txt (including -n option) and cat -b sample-files/3.txt all show slightly different result from yours.

for file_path in args.path:
with open(file_path, "r") as f:
content = f.read()
arrText = content.split("\n")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a method in python to read file into an array of lines directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. I’ll use the built-in method to read the file into a list of lines directly.

arrText = content.split("\n")

if args.b:
for i in range(len(arrText )):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can potentially use enumerate here.

parser.add_argument("path", nargs="?", default=".", help="The directory to list")
args = parser.parse_args()


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, formatting could be improved with ruff here or other formatters :)

)

parser.add_argument("-a", action="store_true", help="include hidden files")
parser.add_argument("-1", dest="one" ,action="store_true", help="use a long listing format")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by long listing format here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your time and help.
I’ll update the help text to reflect that.

import argparse
import os

def show_unhidden_files(listDir):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these two functions be merged into one using extra method param?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion.
I merged them into a single function with an extra parameter.

parser.add_argument("path", nargs="+", default=".", help="The file to count")
args = parser.parse_args()

if not args.l and not args.w and not args.c:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rework this code to have less duplication, by using methods?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback, I’ve refactored the code to reduce duplication.

@@ -0,0 +1,66 @@
import argparse
parser = argparse.ArgumentParser(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please enasure your output is the same as the one suggested for examples in the readme (it is ok if whitespaces are different in your output):

It must act the same as `wc` would, if run from the directory containing this README.md file, for the following command lines:

* `wc sample-files/*`
* `wc -l sample-files/3.txt`
* `wc -w sample-files/3.txt`
* `wc -c sample-files/3.txt`
* `wc -l sample-files/*`

@DaryaShirokova DaryaShirokova added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jan 2, 2026
@aydaeslami aydaeslami added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 4 Assigned during Sprint 4 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants