-
Notifications
You must be signed in to change notification settings - Fork 213
Homework date_files #34
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
base: master
Are you sure you want to change the base?
Conversation
1_date_and_time.py
Outdated
| date_string[4], | ||
| date_string[5], | ||
| ) | ||
| return date_time.strftime("%d.%m.%Y %H:%M:%S") |
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.
лучше использовать datetime.strptime(..., "%")
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.
Опционально можно так сделать: Добавь еще одну функцию def str_2_datetime_simple(), в которой реализуй через strptime, и в main проверь что они одно и тоже возвращают.
Или просто перепиши через strptime
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print_days() |
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.
функция 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) |
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.
вывести отдельно функции подсчета слов и замены знаков
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.
Предлагаю реализовать пункты 3 4 5 отдельными функциями.
И последовательно их вызывать в main.
Должно получиться что-то вроде (псевдокод):
referat = get_file('referat.txt')
word_count = ...
referat_with_all_exclamations = ...
write_to_file('referat2.txt', referat_with_all_exclamations)И уже после этого принты.
1_date_and_time.py
Outdated
|
|
||
| def get_date(count_day=0): | ||
|
|
||
| return datetime.strftime(datetime.now() + count_day * timedelta(days=1), "%d.%m.%Y") |
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.
Функция очень много делает. Она и что-то считает и форматирует. В этом случае оставляем как есть, но обычно можно разнести "форматируем" и "что-то считаем".
Единственное исправление, можно count_day передавать прям в timedelta.
| 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") |
1_date_and_time.py
Outdated
| from datetime import datetime, timedelta | ||
|
|
||
|
|
||
| def get_date(count_day=0): |
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.
naming, название функции не отражает что она делает. Как насчет get_formatted_date_shifted_on(count_day=0):
1_date_and_time.py
Outdated
| pass | ||
|
|
||
| print( | ||
| f"Вчера: {get_date(-1)}, \nСегодня: {get_date()},\n30дней назад: {get_date(-30)}" |
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.
Если хочешь в разных строках, лучше несколько принтов, чем запихивать \n в f-string
1_date_and_time.py
Outdated
| В ней надо заменить pass на ваш код | ||
| """ | ||
| pass | ||
| date_string = date_string.replace("/", " ").replace(":", " ") |
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.
Плюсик за усердность, но тут надо было просто strptime использовать.
1_date_and_time.py
Outdated
| date_string[4], | ||
| date_string[5], | ||
| ) | ||
| return date_time.strftime("%d.%m.%Y %H:%M:%S") |
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.
Опционально можно так сделать: Добавь еще одну функцию 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) |
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.
Предлагаю реализовать пункты 3 4 5 отдельными функциями.
И последовательно их вызывать в main.
Должно получиться что-то вроде (псевдокод):
referat = get_file('referat.txt')
word_count = ...
referat_with_all_exclamations = ...
write_to_file('referat2.txt', referat_with_all_exclamations)И уже после этого принты.
Learn-homework-2