corrupt:3::::5 3 5:1 2 3 4 5 6 7 8" /> corrupt:3::::5 3 5:1 2 3 4 5 6 7 8" /> corrupt:3::::5 3 5:1 2 3 4 5 6 7 8"/>

python handling corruption line

32 Views Asked by At

Do handling Corrupt lines by prepending "corrupt" as the result #Other lines should be handled correctly

#3::::5 => corrupt:3::::5

3 5:1 2 3 4 5 6 7 8 9 Hello World => corrupt:3 5:1 2 3 4 5 6 7 8 9 Hello World

def f10(inFile, outFile):
    try:
        with open(outFile, "w") as op_file:
            for line in open(inFile):
                val = sum_of_factors(
                    *[[int(x) for x in y.split(" ")] for y in line.rstrip().split(":")]
                )
                print(val)
        op_file.write(str(val) + ":" + line.strip() + "\n")
        op_file.close()
    except FileNotFoundError:
        print("Error: Input file not found.")
    except IOError as e:
        print(f"Error: An IO error occurred - {e}")

f10("./input", "./output")

0

There are 0 best solutions below