Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

solution #1

wants to merge 1 commit into from

Conversation

L1nk3rrr
Copy link
Owner

No description provided.

# write your code here
from datetime import datetime
from sys import argv
from os import mkdir, chdir
Copy link
Owner Author

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:
Copy link
Owner Author

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:
Copy link
Owner Author

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"
Copy link
Owner Author

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):
Copy link
Owner Author

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":
Copy link
Owner Author

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])
Copy link
Owner Author

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:
Copy link
Owner Author

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)
Copy link
Owner Author

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:
Copy link
Owner Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants