Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python replace part in large file

for file in files:
    fname = os.path.join(dir, file)
    inFile = codecs.open(fname, "r", "utf-8")
    outFile = codecs.open(fname + ".new", "w", "utf-8")
    for line in inFile:
        newline = do_replacements_on(line)
        outFile.write(newline)
    inFile.close()
    outFile.close()
    os.rename(fname + ".new", fname)
Comment

PREVIOUS NEXT
Code Example
Python :: default argument in flask route 
Python :: openpyxl add worksheet 
Python :: dropping columns in pandas 
Python :: read only the first line python 
Python :: numpy arrays equality 
Python :: how to write to a file in python without deleting all content 
Python :: how to sort in greatest to least python 
Python :: python clear screen windows and linux 
Python :: how to say hello world in python 
Python :: reverse string in python 
Python :: python print do not use scientific notation 
Python :: python read from txt file 
Python :: pygame escape key 
Python :: python GOOGLE_APPLICATION_CREDENTIALS 
Python :: round list of floats python 
Python :: redirect to previous page django 
Python :: how to add up a list in python 
Python :: python run as service windows 
Python :: python csv reader skip header 
Python :: python get random character from string 
Python :: django import csrf exemplt 
Python :: swapcase 
Python :: urlsplit python 
Python :: python join list to string 
Python :: how to get column names having numeric value in pandas 
Python :: python unzip list 
Python :: pop vs remove python 
Python :: how to get all folders on path in python 
Python :: array as an input in python 
Python :: while not equal python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =