Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

change part of a text file python

#!/usr/bin/env python3
import fileinput

with fileinput.FileInput(filename, inplace=True, backup='.bak') as file:
    for line in file:
        print(line.replace(text_to_search, replacement_text), end='')
Comment

PREVIOUS NEXT
Code Example
Python :: changes in settings.py for media storage without db 
Python :: python replace list from another dictionary items 
Python :: how to split a string by colon in python 
Python :: Python NumPy expand_dims Function Example 
Python :: delete file in django terminal 
Python :: sorted multiple keys python 
Python :: Create A Template In Django 
Python :: Accessing of Tuples in python 
Python :: space complexity python 
Python :: pandas weighted average groupby 
Python :: comments in python 
Python :: remove timezone from a datetime object? 
Python :: time conversion 
Python :: NumPy invert Syntax 
Python :: summing all Odd Numbers from 1 to N 
Python :: python iterating through a list 
Python :: oop in python 
Python :: matplotlib.plot python 
Python :: all function in python 
Python :: __dict__ 
Python :: how to use djoser signals 
Python :: polls/models.py 
Python :: pdf to word 
Python :: np.transpose(x) array([[0, 2], [1, 3]]) 
Python :: python OSError: [Errno 22] Invalid argument: 
Python :: add to list in python 
Python :: python array append array 
Python :: self object 
Python :: turn list into string 
Python :: try and exception 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =