Skip to content Skip to sidebar Skip to footer

Python Vertical Txt Concatenation Not Working Properly

There are two solutions from Concatenate tab-delimited txt files vertically Suppose input1 is X\tY input2 is A\tB\r\n C\t\r\n Here, A, B, C are ordinary words and \t is tab. If

Solution 1:

Your first example will work if you add parameter "what chars to strip" in rstrip call. Like this:

    outfile.write(infile.read().rstrip('\r\n') + '\n')

So, the complete example will be:

    filenames = [input1, input2]
    withopen(output, 'w') as outfile:
        for fname in filenames:
            withopen(fname) as infile:
                outfile.write(infile.read().rstrip('\r\n') + '\n')

Post a Comment for "Python Vertical Txt Concatenation Not Working Properly"