-
-
Notifications
You must be signed in to change notification settings - Fork 42
London | SDC-Nov-2025 | Ikenna Agulobi | Sprint 4 | Implement shell tools python #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Sprint-4) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Sprint-4) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
DaryaShirokova
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just added a few comments
| python cat.py sample-files/*.txt | ||
|
|
||
| * Number every line across multiple files(including empty ones) | ||
| python cat.py -n sample-files/*.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a small discrepancy in how you program handles some cases it seems:
$ cat -n sample-files/*.txt
1 Once upon a time...
2 There was a house made of gingerbread.
3 It looked delicious.
4 I was tempted to take a bite of it.
5 But this seemed like a bad idea...
6
7 There's more to come, though...
$ python cat.py -n sample-files/*.txt
1 Once upon a time...
2
3 There was a house made of gingerbread.
4
5 It looked delicious.
6 I was tempted to take a bite of it.
7 But this seemed like a bad idea...
8
9 There's more to come, though...
10
| @@ -0,0 +1,50 @@ | |||
| import argparse | |||
| # ------------------------------------------- | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok to have comments, but it would be even better to have the code split into methods with descriptive names :)
| content = f.read() | ||
|
|
||
| lines = content.split("\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check if you could use readlines method here.
| return args.paths | ||
|
|
||
| # list a single directory | ||
| def list_directory(directory_path, show_hidden, file_per_line): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good as is, but as a suggestion - a tiny bit cleaner approach would be to first get the list of directories/files and for list_directory function to just accept this list and print it (filtering whatever is not needed). This would follow 1 method/1 responsibility paradigm (which helps with code readability / reusability).
|
|
||
|
|
||
| def main(): | ||
| # -------------------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, maybe try splitting into functions instead of comment blocks instead :)
| # -------------------------------------------------------- | ||
| # Print totals if there are multiple files | ||
| # -------------------------------------------------------- | ||
| if len(args.paths) > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there is a way to reuse the same functions (with different args) for printing individual lines and totals
| python wc.py sample-files/* | ||
|
|
||
| * Just lines | ||
| python wc.py -l sample-files/3.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some outputs are different?
wc sample-files/*
1 4 20 sample-files/1.txt
1 7 39 sample-files/2.txt
5 24 125 sample-files/3.txt
7 35 184 total
$ python wc.py sample-files/*
2 4 20 sample-files/1.txt
2 7 39 sample-files/2.txt
6 24 125 sample-files/3.txt
10 35 184 total
Learners, PR Template
Self checklist
Changelist
This PR contains my implementation of cat, ls and wc shell tool commands in python