Skip to content

London | 25-SDC-Nov | Zohreh Kazemianpour | Sprint 4 | Implement Shell Tools-Python#261

Open
zohrehKazemianpour wants to merge 11 commits intoCodeYourFuture:mainfrom
zohrehKazemianpour:shell-Python
Open

London | 25-SDC-Nov | Zohreh Kazemianpour | Sprint 4 | Implement Shell Tools-Python#261
zohrehKazemianpour wants to merge 11 commits intoCodeYourFuture:mainfrom
zohrehKazemianpour:shell-Python

Conversation

@zohrehKazemianpour
Copy link

Self checklist

  • 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 contain implementing Shell tools cat, ls, and wc commands in Python.
This was my first time working with Python! The syntax felt familiar coming from JavaScript, though I had to get used to indentation being required and some differences like len() vs .length.

@zohrehKazemianpour zohrehKazemianpour added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 29, 2025
@LonMcGregor LonMcGregor added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jan 21, 2026
Copy link

@LonMcGregor LonMcGregor left a comment

Choose a reason for hiding this comment

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

Good start on this sprint's tasks, I have spotted a few areas where you could improve code further

numbered_line = f"{line_number:6}\t{line}"
numbered_lines.append(numbered_line)

print("\n".join(numbered_lines)) # LEVEL 3: inside if

Choose a reason for hiding this comment

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

Here you are doing the same thing in both if conditions, setting up a list of lines and then printing. Could you reduce some of the code duplication?

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! I refactored it to use a single output list and one print statement instead of repeating the same code in both conditions.

files = [f for f in files if not f.startswith('.')]

for file in files:
print(file) 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.

Did you test this program without the -1 option?

Copy link
Author

Choose a reason for hiding this comment

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

You're right. It was always printing one per line! Fixed it to use different separators based on the flag.

total_words += words
total_chars += chars

if args.lines:

Choose a reason for hiding this comment

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

Did you test with multiple arguments given at once?

Copy link
Author

Choose a reason for hiding this comment

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

The elif was the problem, only one branch would execute. Switched to independent if statements, so multiple flags work together now.

elif args.chars:
print(f"{total_chars:8} total")
else:
print(f"{total_lines:8}{total_words:8}{total_chars:8} total")

Choose a reason for hiding this comment

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

Do you see the repetition in the structure of the code here? Could that be reduced somehow?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, same duplication issue here. Applied the same fix, building the output dynamically instead of having separate branches for each case.

@LonMcGregor LonMcGregor added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jan 21, 2026
@zohrehKazemianpour
Copy link
Author

Good start on this sprint's tasks, I have spotted a few areas where you could improve code further

Thanks for the review and feedback! I've implemented all the changes you suggested.

@zohrehKazemianpour zohrehKazemianpour added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 8, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants