Skip to content

Conversation

@Geraldine-Edwards
Copy link

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

This PR contains the python exercises in the cat, ls and wc directories of the implement-shell-tools directory

Questions

Any advice for refactoring is welcome!

@Geraldine-Edwards Geraldine-Edwards changed the title Manchester | 25-SDC-Nov | Geraldine Edwards | Sprint 3 | Implement Shell Tools Python Manchester | 25-SDC-Nov | Geraldine Edwards | Sprint 4 | Implement Shell Tools Python Nov 28, 2025
@Geraldine-Edwards Geraldine-Edwards added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 28, 2025
Copy link

@OracPrime OracPrime left a comment

Choose a reason for hiding this comment

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

I can't see anything obviously wrong, but there are a few bits not obviously right that I'm asking for comments on. So this review says (probably) more about my knowledge of how these linuxy things operate than yours. But code should be for the reader, not the writer, so I feel justified in making my comments!



#set locale to the machine default setting
locale.setlocale(locale.LC_ALL, '')

Choose a reason for hiding this comment

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

I'm not familiar with this function. It seems odd that you're having to set something to its default. If it's the default, isn't it already set?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your comments David, much appreciated! So as I was trying to get my LS functionality to sort characters to display the way it mimics actual LS commands, it wasn't behaving the way I expected and so after a bit of research I found that Python doesn't use a computer's language settings by default, it defaults to the 'C' locale. Before it was sorting in ASCII order with capitals before lowercase, the real LS command uses machine's locale settings for sorting. Hope that makes sense?

Choose a reason for hiding this comment

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

It does, and I've learned something today!


# if -a flag set
if args.all:
entries.extend(['.', '..'])

Choose a reason for hiding this comment

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

Doing this review without running the code, so this may be rubbish. But . and .. are current and parent directory. That's not the same as adding hidden files is it? I honestly can't say this is wrong, but I need persuading it's right

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for this David :)
In my code, os.listdir() returns all files and folders in the directory, including hidden files, but it doesn't include the special directory entries (. and .. ), and since the real ls -a command always shows . and .. at the top of the list, I have to add these manually and then sort everything with locale.strxfrm, so that they output the same as the real ls -a output. :)

def calculate_counts(content):
# returns a count object
return {
"lines": content.count('\n') + (1 if content and not content.endswith('\n') else 0),

Choose a reason for hiding this comment

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

I think the code is right, but it's a little obscure. The right of the + probably deserves an explanatory comment

Copy link
Author

Choose a reason for hiding this comment

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

Thanks again, I will add a comment to this along the lines of "count lines by '\n'; add 1 if last line has no newline to match real wc command behavior"
:)

Copy link

@OracPrime OracPrime left a comment

Choose a reason for hiding this comment

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

Good work, and thanks for the education on Python locales!

@OracPrime OracPrime added Reviewed Volunteer to add when completing a review with trainee action still to take. Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 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