-
Notifications
You must be signed in to change notification settings - Fork 0
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
solution #1
base: main
Are you sure you want to change the base?
solution #1
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,56 @@ | ||
# write your code here | ||
from datetime import datetime | ||
from sys import argv | ||
from os import mkdir, chdir | ||
|
||
filename = "" | ||
directories = [] | ||
|
||
if "-f" in argv: | ||
index = 0 | ||
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.
|
||
|
||
for _ in range(len(argv) - 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. too hard reading, try give name of variable, change hard to read construction |
||
index += 1 | ||
if argv[_: _ + 1] == ["-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. better way to find index of |
||
break | ||
|
||
filename = argv[index] | ||
|
||
if "-d" in argv: | ||
index2 = 0 | ||
|
||
for _ in range(len(argv) - 1): | ||
index2 += 1 | ||
if argv[_: _ + 1] == ["-d"]: | ||
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 same about complexity of reading and variable naming |
||
break | ||
|
||
directories = argv[index2:index - 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. can be simplified after refactoring of names, and would be great to set a comment, why you use |
||
else: | ||
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. unnecessary else, use |
||
filename = "file.txt" | ||
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. failed setting filename for file, because |
||
|
||
if "-d" in argv: | ||
index = 0 | ||
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. naming as previous examples |
||
|
||
for _ in range(len(argv) - 1): | ||
index += 1 | ||
if argv[_: _ + 1] == ["-d"]: | ||
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 built-in methods for find position of argument in list |
||
break | ||
|
||
directories = argv[index:len(argv)] | ||
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. no sense to use second arg -> |
||
|
||
file_data = [datetime.today().strftime('%y:%d:%m %H-%M-%S'), "\n"] | ||
|
||
while True: | ||
line = input("Enter content line: ") | ||
if line == "exit": | ||
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. on task was keyword "stop", not "exit" |
||
break | ||
file_data.extend([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. for one line it's better to use |
||
|
||
for directory in directories: | ||
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. try to change that part for using os.makedirs(), instead of creating dir one by one |
||
try: | ||
mkdir(directory) | ||
except Exception: | ||
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. Maybe we can exception particular errors? Try to test your program, and except errors that you will have! |
||
pass | ||
chdir(directory) | ||
|
||
with open(filename, "w") 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. it must create file only when |
||
f.writelines(file_data) | ||
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. Care about a new line ( |
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.
Suggest using absolute import of basic modules for better readability.
sys.argv
more informative than simpleargv
, that can be simple named variable