Jun-28-2024, 04:59 PM
I just noticed this:
Your code needs to pad the line to the desired length minus the suffix.
Quote: I need it to be 88 characters on each line with one of the files ending with N (get 4 files in total a day)Your code does not do this.
Your code needs to pad the line to the desired length minus the suffix.
def reformat_file(filename, length=88, suffix=""): length = length - len(suffix) lines = [] with open(filename, "r") as fp: for line in fp: lines.append(line[:length].strip().ljust(length) + suffix) with open(filename, "w") as fp: fp.write("\n".join(lines)) if __name__ == "__main__": import sys filename = sys.argv[1] suffix = "N" if filename == "Nfile.txt" else "" reformat_file(filename, suffix=suffix)