Skip to content

Lesson5 - #4

Open
SRytv wants to merge 7 commits into
masterfrom
lesson5
Open

Lesson5#4
SRytv wants to merge 7 commits into
masterfrom
lesson5

Conversation

@SRytv

@SRytv SRytv commented Sep 20, 2018

Copy link
Copy Markdown
Owner

No description provided.

Comment thread Lesson5/SRHw05_easy.py

def make_dir(dir_path):
if os.path.exists(dir_path):
result = 2 # Error: a directory with the same name is already exists

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это C-way (ну или С++) разработки. Возвращение кода. Лучше разнесите на функции, типа path_exists. И Exception если директория не создалась - лучше не замалчивать. Обычно это ведёт лишь к дальнейшим ошибкам в выполнении программы.

Comment thread Lesson5/les5_hard.py
dir_path = ' '
def is_abs_filename(file_or_dir):
# возвращает 1 если это абсолютная директория, и 0 если относительная
pattern = re.compile(r'[A-Z]:\)', re.IGNORECASE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.path.isabs есть такой метод в python. Можно пользоваться им)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Но круто что воспользовались regex. Это полезно, как показало ваше расследование)

Comment thread Lesson5/les5_hard.py
else:
print("Вы действительно хотите удалить директорию '{}'".format(file_dir_name))
answer = input("Ведите 'Y', если 'да' или 'N', если нет:")
if answer =='N' or answer == 'N':

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше делать так, во избежании ошибок, как тут) Это обычная практика, рекомендую взять на вооружение
answer.lower() == 'N'.lower()

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, спасибо! Я совершенно забыл, сто у литералов и строк можно менять регистр с большого верхнего на нижний и наоборот...

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