Q:

How would I go about re-writing a file so that it may become more manageable?

The problem Is that I am trying to write code so that my .txt file will be re-written into a more manageable version of itself. The 'program' needs to read seven lines at a time and then write it out as a single line in another .txt file then repeat this function until it has gone through the entire .txt file.    
I have been looking all over the internet and have tried multiple things however none of it even comes close to what I need the closest I've gotten is with the following code.
first_line = 7

def function():

    with open ('file_txt', 'r') as read_file1:

            line = [next(read_file1) for x in range(first_line)]

            with open ('file_txt_new', 'w') as write_file2:

                    write_file2.write(str(line))

The input text file looks like this:
Awakened Shrub
Small plant, unaligned
Hit Points:
10 (3d6) Armor Class:
9 Speed:
20 ft. Challenge Rating:
0 (10 XP)

expected results: these results are simply the original text file being       re-writen in a single line.
example 1: This would be written on line one of the new text document.  
Awakened Shrub, Small plant, unaligned, Hit Points: 10 (3d6) Armour Class: 9

example 2: This would be written on line two of the new text document.
Baboon, Small beast, unaligned, Hit Points: 1 (1d4 - 1) Armour Class: 9

actual results:
['Awakened Shrub\n', 'Small plant, unaligned\n', 'baboon\n', 'Small beast, unaligned\n',]

A:

I think the following code helps you:
num_reads = 7
with open('data.txt') as read_file:
    with open('new_data.txt', 'w') as write_file:

        while (True):
            lines = []
            try:       # You should expect errors if the number of lines in the file are not a multiplication of num_reads
                for i in range(num_reads):     
                    lines.append(next(read_file))  # when the file finishes an exception occurs here

                #do sutff with the lines (exactly num_reads number of lines)
                processed = " ".join(list(map(lambda x: x.replace("\n", ''), lines)))
                write_file.write(processed + '\n')

            except StopIteration:     # here we process the (possibly) insufficent last lines
                #do stuff with the lines (less that  num_reads)
                processed = " ".join(list(map(lambda x: x.replace("\n", ''), lines)))
                write_file.write(processed + '\n')
                break

When the end of file is reached a StopIteration error is raised and caught by except where you can process the possible insufficient lines of data captured and break out of the while loop. In the above piece of code, I did the same operation on both full (num_reads = 7) captures and the partial ones. The processing part just attaches the lines and removes newline characters.
When data.txt is like this:
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10

new_data.txt will be like this:
line1 line2 line3 line4 line5 line6 line7
line8 line9 line10

