Q:

How do I split a text file into multiple text files by 25 lines using python?

I have a text file lets say FileA.txt. I want to split this txt file at every 25 lines so Line 0-25 will be File1.txt, Lines 26-50 will be File2.txt and so on.
I have attempted to follow:
Splitting large text file into smaller text files by line numbers using Python
But have not had much luck. My python skills are pretty basic and low-level.
When I ran it I got the following error:
"", line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape 
Then I added an r like so with open(r'C:\Users and now I get PermissionError: [Errno 13] Permission denied: 'C:\Users\joker\Desktop\LiveStream_Videos'

A:

You could try chunking every 25 lines, then write them each out to separate files:
def chunks(l, n):
    """Chunks iterable into n sized chunks"""
    for i in range(0, len(l), n):
        yield l[i:i + n]

# Collect all lines, without loading whole file into memory
lines = []
with open('FileA.txt') as main_file:
    for line in main_file:
        lines.append(line)

# Write each group of lines to separate files
for i, group in enumerate(chunks(lines, n=25), start=1):
    with open('File%d.txt' % i, mode="w") as out_file:
        for line in group:
            out_file.write(line)

Note: The chunking recipe from How do you split a list into evenly sized chunks?. 

