Current location - Music Encyclopedia - Chinese History - Python reads the same column of data in each row of the document, merges it end to end, and then outputs it to another file.
Python reads the same column of data in each row of the document, merges it end to end, and then outputs it to another file.
def? zhidao_556225095(infile,? Output file):

Readers? =? Open (infile, r')

A writer? =? Open (outfile, w')

buff? =? []

buff_size? =? 1000#? The file is too large, and the output is cached in the block.

What time? True:

Line? =? reader.readline()

What if? Len (line)? ==? 0:

break

Field? =? line.split()[2]

buff.append(field.strip())

What if? len(buff)? & gt=? buff_size:

writer.write(')。 Buff)

buff? =? []

Otherwise:

writer.write(')。 Buff)

writer.close()

reader.close()