Skip to content

Conversation

@StasiaSol
Copy link

Learn-homework-2

date_string[4],
date_string[5],
)
return date_time.strftime("%d.%m.%Y %H:%M:%S")
Copy link

Choose a reason for hiding this comment

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

лучше использовать datetime.strptime(..., "%")

Copy link

Choose a reason for hiding this comment

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

Опционально можно так сделать: Добавь еще одну функцию def str_2_datetime_simple(), в которой реализуй через strptime, и в main проверь что они одно и тоже возвращают.
Или просто перепиши через strptime



if __name__ == "__main__":
print_days()
Copy link

Choose a reason for hiding this comment

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

функция str_2_datetime не вызывается

2_files.py Outdated
print(len(context.split()))
context = context.replace(".", "!")
with open("referat2.txt", "w", encoding="utf-8") as file2:
file2.write(context)
Copy link

Choose a reason for hiding this comment

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

вывести отдельно функции подсчета слов и замены знаков

Copy link

Choose a reason for hiding this comment

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

Предлагаю реализовать пункты 3 4 5 отдельными функциями.
И последовательно их вызывать в main.
Должно получиться что-то вроде (псевдокод):

referat = get_file('referat.txt')
word_count = ...
referat_with_all_exclamations = ...
write_to_file('referat2.txt', referat_with_all_exclamations)

И уже после этого принты.


def get_date(count_day=0):

return datetime.strftime(datetime.now() + count_day * timedelta(days=1), "%d.%m.%Y")
Copy link

Choose a reason for hiding this comment

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

Функция очень много делает. Она и что-то считает и форматирует. В этом случае оставляем как есть, но обычно можно разнести "форматируем" и "что-то считаем".

Единственное исправление, можно count_day передавать прям в timedelta.

Suggested change
return datetime.strftime(datetime.now() + count_day * timedelta(days=1), "%d.%m.%Y")
return datetime.strftime(datetime.now() + timedelta(days=count_day), "%d.%m.%Y")

from datetime import datetime, timedelta


def get_date(count_day=0):
Copy link

Choose a reason for hiding this comment

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

naming, название функции не отражает что она делает. Как насчет get_formatted_date_shifted_on(count_day=0):

pass

print(
f"Вчера: {get_date(-1)}, \nСегодня: {get_date()},\n30дней назад: {get_date(-30)}"
Copy link

Choose a reason for hiding this comment

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

Если хочешь в разных строках, лучше несколько принтов, чем запихивать \n в f-string

В ней надо заменить pass на ваш код
"""
pass
date_string = date_string.replace("/", " ").replace(":", " ")
Copy link

Choose a reason for hiding this comment

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

Плюсик за усердность, но тут надо было просто strptime использовать.

date_string[4],
date_string[5],
)
return date_time.strftime("%d.%m.%Y %H:%M:%S")
Copy link

Choose a reason for hiding this comment

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

Опционально можно так сделать: Добавь еще одну функцию def str_2_datetime_simple(), в которой реализуй через strptime, и в main проверь что они одно и тоже возвращают.
Или просто перепиши через strptime

2_files.py Outdated
print(len(context.split()))
context = context.replace(".", "!")
with open("referat2.txt", "w", encoding="utf-8") as file2:
file2.write(context)
Copy link

Choose a reason for hiding this comment

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

Предлагаю реализовать пункты 3 4 5 отдельными функциями.
И последовательно их вызывать в main.
Должно получиться что-то вроде (псевдокод):

referat = get_file('referat.txt')
word_count = ...
referat_with_all_exclamations = ...
write_to_file('referat2.txt', referat_with_all_exclamations)

И уже после этого принты.

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.

3 participants