-
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 1 commit
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,42 @@ | ||
| # write your code here | ||
| import os | ||
| import sys | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| def create_file() -> 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 | ||
|
|
||
| path = os.path.join(*dirs) if dirs else "" | ||
| if path: | ||
| os.makedirs(path, exist_ok=True) | ||
|
|
||
| full_path = os.path.join(path, filename) | ||
|
|
||
| line_number = 1 | ||
| file_exists = os.path.exists(full_path) | ||
| with open(full_path, "a", encoding="utf-8") as file: | ||
| timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | ||
| if file_exists: | ||
| file.write("\n") | ||
| file.write(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 | ||
|
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 violates the 'Don't Repeat Yourself' section: 'Create separate functions in order not to have repeating blocks of code.' The code has all logic in one function without separating concerns (argument parsing, directory creation, file writing). Consider creating separate functions for these distinct operations. |
||
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.