London | 26-March-SDC | Ammad Ur Rehman | Sprint 4 | Implement shell tools (cat, ls, wc) in Python - #540
London | 26-March-SDC | Ammad Ur Rehman | Sprint 4 | Implement shell tools (cat, ls, wc) in Python#540anosidium wants to merge 14 commits into
Conversation
SlideGauge
left a comment
There was a problem hiding this comment.
Good job, left several comments, could you fix them please?
| continue | ||
|
|
||
| with open(path, "r") as file: | ||
| line_number = 1 |
There was a problem hiding this comment.
README requires cat -n sample-files/*.txt to behave like real cat -n, which numbers lines continuously across all files
There was a problem hiding this comment.
Real cat produces:
cat -n sample-files/*.txt
1 Once upon a time...
1 There was a house made of gingerbread.
1 It looked delicious.
2 I was tempted to take a bite of it.
3 But this seemed like a bad idea...
4
5 There's more to come, though...Python cat produces:
python3 cat.py -n sample-files/*.txt
1 Once upon a time...
1 There was a house made of gingerbread.
1 It looked delicious.
2 I was tempted to take a bite of it.
3 But this seemed like a bad idea...
4
5 There's more to come, though...The only difference is the indentation.
|
|
||
| args = parser.parse_args() | ||
|
|
||
| entries = os.listdir(args.filepath) |
There was a problem hiding this comment.
Does os.listdir return dir list in an alphabetical order? Compare with what real ls does
There was a problem hiding this comment.
When I run ls -a, it produces:
. ls.py README.md
.. node_modules sample-filesWhen I run the Python variant, python3 ls.py -a:
. .. README.md ls.py node_modules sample-filesThe alphabetically ordering does not match.
|
Thanks for the review. I've made some changes. |
|
|
||
| try: | ||
| with open(path, "r") as file: | ||
| line_number = 1 |
There was a problem hiding this comment.
numbering still restarts per file, not continuous.
There was a problem hiding this comment.
Sorry, I’m going to have to disagree with this one. The program matches the behaviour of cat on my system. I checked all the commands in README.md and the output matches.
If I move line_number = 1 outside the loop, the numbering becomes continuous across files and no longer matches cat.
My Python implementation:
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...
cat:
1 Once upon a time...
1 There was a house made of gingerbread.
1 It looked delicious.
2 I was tempted to take a bite of it.
3 But this seemed like a bad idea...
4
5 There's more to come, though...
So keeping line_number = 1 inside the per-file loop is what makes my implementation match cat on macOS. This may be a GNU/Linux vs BSD/macOS difference.
|
@cjyuan Could you please review my pull request? Thank you. |
|
@SlideGauge Could you please review my pull request? Thank you. |
|
Note: It's an GNU/Linux vs BSD/macOS issue. The curriculum team said for the past cohort, either version is acceptable. So I am marking this PR as "Complete". |
|
Your PR didn't include a Task ID in its description. Make sure you have put the correct Task ID in its description. 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. |
Learners, PR Template
Self checklist
Changelist
Reimplement the shell programs as a Python program.