Skip to content

London | 26-SDC-Mar | Khilola Rustamova| Sprint 3 |Implement shell tools python#537

Open
HilolaRustam wants to merge 5 commits into
CodeYourFuture:mainfrom
HilolaRustam:implement-shell-tools-python
Open

London | 26-SDC-Mar | Khilola Rustamova| Sprint 3 |Implement shell tools python#537
HilolaRustam wants to merge 5 commits into
CodeYourFuture:mainfrom
HilolaRustam:implement-shell-tools-python

Conversation

@HilolaRustam

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

Briefly explain your PR.

implementation of cat, ls and wc with python

Questions

@HilolaRustam HilolaRustam added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Tools The name of the module. 📅 Sprint 3 Assigned during Sprint 3 of this module labels Jun 10, 2026
@illicitonion illicitonion 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 Jun 10, 2026

@illicitonion illicitonion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is generally looking good, and like things work :) I left a few style comments, and many of my comments to one project apply to the others as well.

return sorted(files)

def read_lines(file):
with open(file, "r", encoding="utf-8") as f:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This block is more indented than the others - why is that?

try:
lines = read_lines(file)
except FileNotFoundError:
print(f"cat: {file}: No such file or directory", file=sys.stderr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good job printing to stderr not stdout :)

However! If you ran into an issue here, I think your program will still exit with exit code 0. What exit code do you think it should exit with?

sys.stdout.write(prefix + line)


def main():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This all works, but often people will have their main function at the top of the file so it's the first thing you read, and allow you to scroll down to read details if needed. You don't need to follow this, but it can often make it easier to read/review code.

paths.append(a)

files = expand_paths(paths)
print_lines(files, number_all,number_nonempty)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've noticed your whitespace is a bit inconsistent (e.g. no space after this ,) - you may want investigate a tool like black to help automate fixing this.

number_all = True
elif a == "-b":
number_nonempty = True
number_all = False #-b overrides -n

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What would happen if -b appeared before -n in the command line?

paths.append(a)

files = expand_paths(paths)
print_lines(files, number_all,number_nonempty)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We often used named arguments in Python when we have multiple arguments of the same type, to make sure we don't accidentally pass them in the wrong order. If you wrote print_lines(files, number_nonempty, number_all) here it wouldn't be obvious that the order was swapped. Instead we can write:

print_lines(files, number_all=number_all, number_nonempty=number_nonempty)

and if we swapped them by mistake it would be obvious.

def list_dir(path, show_all=False, one_per_line = False):
try:
entries = os.listdir(path)
except FileNotFoundError:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question as above about exit codes.

@illicitonion illicitonion 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 Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Tools The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants