How to remove blank line in a text file (.txt file)

from sys import argv
script, input_encoding, error = argv
def main(file1, file2, encoding, errors):
    line = file1.readline()
    if line:
        convert_and_write(line, file2, encoding, errors)
        return main(file1, file2, encoding, errors)
def convert_and_write(line, file2, encoding, errors):
    next_lang = line.strip()
    raw = next_lang.encode(encoding, errors = errors)
    file2.writelines(str(raw) + "\n")
with open("1.txt", "w") as f, open("ex23_sample.txt", encoding = "utf-8") as g:
    main(g, f, input_encoding, error)

What i’m trying to do is to encode strings (in ex23_sample.txt) to b’ ’ bytes and write all of them into the file 1.txt, each on a separate line (using \n). The code did do the job but it also created a blank line (without white space) in the end of the file 1.txt. I’ve tried many methods I found on google to remove it (the blank line) but none works. Can anyone help me? Big THANKS!

A quick look and I think just ditch the + "\n" in the file2.writelines call.