Replace line in file using re

Why is my code not working properly? I'm trying to replace one line in file using the re module:

import re

file = open("php.ini", "r+")

pattern = r'post_max_size = [0-9]'
result = re.search(pattern, file.read())

for line in file:        
    re.sub(pattern, "post_max_size = 1G", file.read())

file.close()
print(result)

I have done this by using the fileimport library, but this is not the way. Why can't it run properly while pattern is printing good result and re.sub() should replace it in this place in file?



from Recent Questions - Stack Overflow https://ift.tt/3hh0qja
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations