generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 42
London|25-SDC-NOV| FATMA DEGIRMENCI | Sprint 4|IMPLEMENT_SHELL_TOOLS Python #289
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
Open
fatmaevin
wants to merge
3
commits into
CodeYourFuture:main
Choose a base branch
from
fatmaevin:shell-tools-python
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .venv/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import argparse | ||
| import glob | ||
|
|
||
|
|
||
| parser = argparse.ArgumentParser(description="cat command") | ||
| parser.add_argument("files", nargs="+", help="Files to read") | ||
| parser.add_argument("-n", action="store_true", help="Number all lines") | ||
| parser.add_argument("-b", action="store_true", help="Number non-empty lines") | ||
| args = parser.parse_args() | ||
|
|
||
|
|
||
| files = [] | ||
| for pattern in args.files: | ||
| files.extend(glob.glob(pattern)) | ||
|
|
||
|
|
||
| line_number = 1 | ||
|
|
||
| for file in files: | ||
| with open(file, "r") as f: | ||
| for line in f: | ||
| line_content = line.rstrip("\n") | ||
|
|
||
| if args.b and line_content != "": | ||
| print(f"{line_number}\t{line_content}") | ||
| line_number += 1 | ||
| elif args.n: | ||
| print(f"{line_number}\t{line_content}") | ||
| line_number += 1 | ||
| else: | ||
| print(line_content) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import argparse | ||
| import os | ||
| parser=argparse.ArgumentParser(description="ls command") | ||
| parser.add_argument("-1",dest="one_per_line",action="store_true",help="List one file per line") | ||
| parser.add_argument("-a",dest="all", action="store_true",help="Include hidden files") | ||
| parser.add_argument("path", nargs="?", default=".", help="Directory to list") | ||
|
|
||
| args=parser.parse_args() | ||
| files=os.listdir(args.path) | ||
| if not args.all: | ||
| new_files=[] | ||
| for f in files: | ||
| if not f.startswith("."): | ||
| new_files.append(f) | ||
| files=new_files | ||
| if args.one_per_line: | ||
| for f in files: | ||
| print(f) | ||
| else: | ||
| print(" ".join(files)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import argparse | ||
| import os | ||
|
|
||
| parser = argparse.ArgumentParser(description="wc command") | ||
| parser.add_argument("file", help="File or directory to read") | ||
| parser.add_argument("-l", dest="lines", action="store_true", help="count the number of lines") | ||
| parser.add_argument("-w", dest="words", action="store_true", help="count the number of words") | ||
| parser.add_argument("-c", dest="chars", action="store_true", help="count the number of characters") | ||
| args = parser.parse_args() | ||
|
|
||
| if os.path.isdir(args.file): | ||
| files = os.listdir(args.file) | ||
| for f in files: | ||
| path = os.path.join(args.file, f) | ||
| if os.path.isfile(path): | ||
| with open(path, "r") as file_obj: | ||
| text = file_obj.read() | ||
| line_count = len(text.splitlines()) | ||
| word_count = len(text.split()) | ||
| char_count = len(text) | ||
|
|
||
| if not (args.lines or args.words or args.chars): | ||
| print(f"{line_count}\t{word_count}\t{char_count}\t{path}") | ||
| continue | ||
| output = [] | ||
| if args.lines: | ||
| output.append(str(line_count)) | ||
| if args.words: | ||
| output.append(str(word_count)) | ||
| if args.chars: | ||
| output.append(str(char_count)) | ||
| output.append(path) | ||
| print("\t".join(output)) | ||
| else: | ||
|
|
||
| with open(args.file, "r") as f: | ||
| text = f.read() | ||
| line_count = len(text.splitlines()) | ||
| word_count = len(text.split()) | ||
| char_count = len(text) | ||
| if not (args.lines or args.words or args.chars): | ||
| print(f"{line_count}\t{word_count}\t{char_count}\t{args.file}") | ||
| else: | ||
| output = [] | ||
| if args.lines: | ||
| output.append(str(line_count)) | ||
| if args.words: | ||
| output.append(str(word_count)) | ||
| if args.chars: | ||
| output.append(str(char_count)) | ||
| output.append(args.file) | ||
| print("\t".join(output)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part at the end seems repeated. Is there something you could do to simplify this? |
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean to commit all these blank lines at the end? |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you see the duplication in these two branches of code. Is there some way to simplify this?