Skip to content

London | 26-Jul-SDC | Roman Sanaye | Sprint 4 | Implement shell tool in Python - #637

Open
RomanSanaye wants to merge 6 commits into
CodeYourFuture:mainfrom
RomanSanaye:implement-shell-tools-python
Open

London | 26-Jul-SDC | Roman Sanaye | Sprint 4 | Implement shell tool in Python#637
RomanSanaye wants to merge 6 commits into
CodeYourFuture:mainfrom
RomanSanaye:implement-shell-tools-python

Conversation

@RomanSanaye

@RomanSanaye RomanSanaye commented Jul 30, 2026

Copy link
Copy Markdown

Learners, PR Template

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

Changelist

Implemented the wc shell tool using Python.

The implementation supports:

  • Reading command-line arguments
  • Separating flags and file paths
  • Counting lines, words, and characters
  • Supporting -l, -w, and -c flags
  • Handling multiple files and displaying total counts

I tested the program against the required commands:

  • 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/*
  • wc -w -l sample-files/3.txt
  • wc -w -l sample-files/*

Questions

No questions.

Task ID: CYF-1152

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 30, 2026

@LonMcGregor LonMcGregor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good start, but some things to fix.

also, Is the choice you have used for processing arguments the most effective? Is there a library you could use to help the implementation?

Comment thread implement-shell-tools/wc/wc.py Outdated
# Print total only when multiple files
if len(paths) > 1:

total_output = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think about the output code here? Can you spot any duplication across the file?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks. I removed the duplicated output logic by creating a get_output() function.


else:
if "-l" in flags:
output.append(lines)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you run this with multiple files, how does the output look? What change could make it neater?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks. I’ve updated the output formatting to make the results neater when using multiple files.

@LonMcGregor LonMcGregor 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 Aug 3, 2026
@RomanSanaye

Copy link
Copy Markdown
Author

Good start, but some things to fix.

also, Is the choice you have used for processing arguments the most effective? Is there a library you could use to help the implementation?

Hi sir @LonMcGregor
Thanks for the feedback. I’ve changed the manual argument processing to use argparse.

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 4, 2026

@LonMcGregor LonMcGregor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These argparse implementations are better, and good idea in wc to write a function to handle printing output to reduce duplication.

I have some concern that you are not using the argparse library to best effect.

In particular, if we look at the cat implementation, you use this:

if args.n:
    flag = "-n"

followed later by

if flag == "-n":

Is storing things as strings even necessary when you are using a library to help you in this way?

Similar issues exist across the other implementations.

@LonMcGregor LonMcGregor removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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