-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Solution #1769
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: master
Are you sure you want to change the base?
Solution #1769
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,61 @@ | ||
| # write your code here | ||
| import os | ||
| import sys | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| def parse_arguments(argv: str) -> str | None: | ||
| i = 1 | ||
| dirs = [] | ||
| filename = None | ||
| while i < len(sys.argv): | ||
| if sys.argv[i] == "-d": | ||
| i += 1 | ||
| while (i < len(sys.argv)) and not sys.argv[i].startswith("-"): | ||
| dirs.append(sys.argv[i]) | ||
| i += 1 | ||
| continue | ||
| elif sys.argv[i] == "-f": | ||
| filename = sys.argv[i + 1] | ||
| i += 2 | ||
| continue | ||
| i += 1 | ||
| return dirs, filename | ||
|
|
||
|
|
||
| def build_path(dirs: list, filename: str) -> str | bytes: | ||
| path = os.path.join(*dirs) if dirs else "" | ||
| if path: | ||
| os.makedirs(path, exist_ok=True) | ||
|
|
||
| return os.path.join(path, filename) | ||
|
|
||
|
|
||
| def write_content(full_path: str) -> None: | ||
| line_number = 1 | ||
| file_exists = os.path.exists(full_path) | ||
|
|
||
| with open(full_path, "a", encoding="utf-8") as file: | ||
| if file_exists: | ||
| file.write("\n") | ||
|
|
||
| timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | ||
| file.write(f"{timestamp}\n") | ||
|
|
||
| while True: | ||
| user_input = input("Enter content line: ") | ||
|
|
||
| if user_input.lower() == "stop": | ||
|
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. Single quote used here. Per checklist requirements, double quotes should be used consistently throughout the code. |
||
| break | ||
|
|
||
| file.write(f"{line_number}. {user_input}\n") | ||
|
Comment on lines
+49
to
+50
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. Line numbers have a period after them ( |
||
| line_number += 1 | ||
|
|
||
|
|
||
| def create_file() -> None: | ||
|
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 function is defined but never called. Add |
||
| dirs, filename = parse_arguments(sys.argv) | ||
| full_path = build_path(dirs, filename) | ||
| write_content(full_path) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| create_file() | ||
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.
This violates checklist item #1 under Code Style: 'Use one style of quotes in your code. Double quotes are preferable.' Single quotes are used here while double quotes are used elsewhere in the file.