I have a text file which is about 400,000 lines long. I need to import this text file into a program which only accepts text files which are delimited with spaces or tabs, b
Python 3.2 has added ability to use this as context manager, so that the files that fail during processing for some reason will always get closed:
import fileinput
def main():
with fileinput.input(inplace=True) as f:
for line in f:
line = line.replace(";", " ")
print(line, end='')
(inspiration)
Use it by supplying it with the text file you want to process.