From Stack Overflow
# replace ":" separator with space-padded " : " # Read in the file filename = 'scratch/nhoodCOzone_1.txt' with open(filename, 'r') as file : filedata = file.read() # Replace the target string filedata = filedata.replace(':', ' : ') # Write the file out filename = 'scratch/nhoodCOzone.txt' with open(filename, 'w') as file: file.write(filedata)