-
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
Conversation
# write your code here | ||
from datetime import datetime | ||
from sys import argv | ||
from os import mkdir, chdir |
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 simple argv
, that can be simple named variable
break | ||
|
||
directories = argv[index2:index - 1] | ||
else: |
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.
unnecessary else, use elif -d in argv
, for simply note that only one param was enterd by console
pass | ||
chdir(directory) | ||
|
||
with open(filename, "w") as f: |
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.
it must create file only when -f
was passed into arguments, not every time of running script.
Also, you 'a'
mode for opening file, for appending text! For now, you every time rewrite file, so old file info would be deleted on new write.
|
||
directories = argv[index2:index - 1] | ||
else: | ||
filename = "file.txt" |
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.
failed setting filename for file, because -f
argument wasn't pulled
if "-f" in argv: | ||
index = 0 | ||
|
||
for _ in range(len(argv) - 1): |
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.
too hard reading, try give name of variable, change hard to read construction for _ in range(len(argv) - 1):
|
||
while True: | ||
line = input("Enter content line: ") | ||
if line == "exit": |
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.
on task was keyword "stop", not "exit"
line = input("Enter content line: ") | ||
if line == "exit": | ||
break | ||
file_data.extend([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.
for one line it's better to use .append()
method, read about difference of extend
and append
methods of list
break | ||
file_data.extend([line]) | ||
|
||
for directory in directories: |
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.
try to change that part for using os.makedirs(), instead of creating dir one by one
chdir(directory) | ||
|
||
with open(filename, "w") as f: | ||
f.writelines(file_data) |
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.
Care about a new line ('\n'
) at the end of your file_data, to beautify output file with new lines. Or just iterate through file_data and do every line write
for directory in directories: | ||
try: | ||
mkdir(directory) | ||
except Exception: |
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.
Maybe we can exception particular errors? Try to test your program, and except errors that you will have!
No description provided.