How to search and Replace text in a file in Python

preview_player
Показать описание
In this video we will learn how to search and Replace text in a file in Python.
Рекомендации по теме
Комментарии
Автор

Thank you this helped me with my current project!

aidendouglas
Автор

It works absolutely fine, thank you :)

sriyapradhan
Автор

Great powerful code! However, when I try to put it in a loop to do multiple text files I get this error message "PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:"
A little research tells me the file in use isn't being closed before going on to the next file.
I've tried using "line.close()", "sys.exit()", "yield", "fileinput.close()", and "return", but none of them are working. How do I close the text file after processing? Thanks...

DGA
Автор

Hello! In a txt file, how can I replace from the first character to any special character ", ", ?

levil
Автор

it didn't work for me? why is that

Natness
Автор

get always error: TypeError: string indices must be integers

CB-ohdw