-
Notifications
You must be signed in to change notification settings - Fork 1.6k
no tests #1767
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?
no tests #1767
Changes from 5 commits
caca881
8175ab8
e8e3e75
ea49dec
013e9a7
fee429b
d75b9b1
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,62 @@ | ||
| # write your code here | ||
| from sys import argv, exit | ||
| from os import makedirs, path # , getcwd | ||
| from datetime import datetime | ||
|
|
||
| # argv = ["app/create_file.py", "-f ", " file.txt"] | ||
|
|
||
| if len(argv) <= 2 : | ||
| print("Usage: -f <filename> or/and -d <directory>") | ||
| exit(0) | ||
|
|
||
| filename = "" | ||
| directory = [] | ||
| stop = False | ||
| content = [] | ||
| line_number = 1 | ||
|
|
||
| del argv[0] | ||
|
|
||
| for index in range(len(argv)): | ||
| if argv[index] == "-f": | ||
| try: | ||
| filename = argv[index + 1].strip().lower() | ||
| del argv[index: index + 2] | ||
| break | ||
| except IndexError: | ||
| print("Error: correct format -f <filename>") | ||
| exit(1) | ||
|
|
||
| for index in range(len(argv)): | ||
| if argv[index].strip() == "-d": | ||
| if index == len(argv) - 1: | ||
| print("Error: correct format -d <directory name(s)>") | ||
| exit(1) | ||
| directory = [name.strip() for name in argv[index + 1:]] | ||
|
|
||
| # print(f"Path: {path.join(*directory, filename)}") | ||
| # print(f"file: {filename}") | ||
|
|
||
| if directory != []: | ||
| makedirs(path.join(*directory), exist_ok=True) | ||
|
|
||
| if filename != "": | ||
| full_path = path.join(*directory, filename) | ||
|
|
||
| while not stop: | ||
| line = input("Enter content line: ") | ||
| if line.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. Use double quotes consistently as per the checklist requirement. |
||
| stop = True | ||
| else: | ||
| content.append(f"\n{line_number} {line}") | ||
| line_number += 1 | ||
| # content.append("\n") | ||
|
|
||
| # current_dir = getcwd() | ||
| # print(current_dir) | ||
|
|
||
| with open(full_path, "a") as f: | ||
|
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. When appending to an existing file, there's no blank line added before the new timestamp. Per the requirements example, there should be a blank line between content batches. Consider checking if file exists and adding separator. |
||
| f.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) | ||
|
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. The timestamp is written without a trailing newline (line 57), but first content line has |
||
| for line in content: | ||
| f.write(line) | ||
|
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. CHECKLIST ITEM #5 VIOLATION: The code doesn't use separate functions for reusable operations. Per the checklist 'Create separate functions in order not to have repeating blocks of code', extract content collection into |
||
|
|
||
| # print("Finish") | ||
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.
CRITICAL BUG: This logic is broken when
-dcomes before-f. Therange(len(argv))is evaluated once at loop start, but argv elements are deleted in the first loop. When-dappears first (e.g.,['-d', 'dir1', '-f', 'file.txt']), after processing-d, the code tries to access indices beyond the shortened list, causing IndexError. Fix: collect-darguments until another flag is encountered, not all remaining args.