Skip to content

Conversation

@dimamushalapugin
Copy link

No description provided.

Copy link

@krepysh krepysh left a comment

Choose a reason for hiding this comment

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

Принято. Можно что-то поулучшать, но и так ок.


replace_example = context.replace('.', '!')
print(replace_example)
with open('referat1.txt', 'w', encoding='utf-8') as new_f:
Copy link

Choose a reason for hiding this comment

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

здесь так же можно использовать as f, потому что область видимости предыдущего f только блок with

В ней надо заменить pass на ваш код
"""
pass
with open('referat.txt', 'r', encoding='utf-8') as f:
Copy link

Choose a reason for hiding this comment

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

Должно ок работать без указания кодировки. Если не указываешь кодировку - код чутьчуть универсальнее получается.

context = f.read()
print(len(context))
number_of_words = len(context.split())
print(f'Количество слов составляет - {number_of_words}')
Copy link

Choose a reason for hiding this comment

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

Попробуй выделить отдельные функции: read_file, write_file, process_file_content

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