Beginner issues with python script output
Question: The below Python code isn't acting as intended.

The final output is missing all lines that I'd expect to be outputted where
`output_data[1] == "S"`.

It also appears my lazy attempt to obfuscate client ID is failing.

    
    
    import csv
    
    TID = 0
    ACCT_TYPE = 1
    PRODUCT_TYPE = 2
    NUM_ACCT_OWNERS = 3
    NUM_ACCT = 4
    COMBINED_BALANCES = 5
    TID_BALANCES = 6
    INSURED_BALANCES = 7
    ESTIMATED_UNINSURED = 8
    FOREIGN_IND = 9
    
    #output_data = [None] * 10
    
    header_row_processed = False
    
    with open("U:\exampletext.txt", 'r') as csvfile:
    CIN = csv.reader(csvfile, delimiter="\t")
    file_output_data = []
    for row in CIN:
    
        if not header_row_processed:
            header_row_processed = True
            continue
    
        if not row[ACCT_TYPE] == "I" or row[ACCT_TYPE] == "S":
             continue
    
        if not row[PRODUCT_TYPE] == "Total":
             continue
    
        output_data = [None] * 6
    
        client_id = row[TID]
        client_id.replace("0", "x")
        client_id.replace("1", "d")
        client_id.replace("2", "h")
        client_id.replace("3", "g")
        client_id.replace("4", "v")
        client_id.replace("5", "n")
        client_id.replace("6", "m")
        client_id.replace("7", "q")
        client_id.replace("8", "w")
        client_id.replace("9", "r")
        client_id.replace("-", "u")
        output_data[0] = client_id
    
        output_data[1] = row[ACCT_TYPE]
    
        output_data[2] = row[PRODUCT_TYPE]
    
        output_data[3] = row[COMBINED_BALANCES]
    
        output_data[4] = str(min(float(row[COMBINED_BALANCES])/float(row[NUM_ACCT_OWNERS]), 250000*float(row[NUM_ACCT_OWNERS])))
    
        output_data[5] = str(max(0, (float(row[COMBINED_BALANCES])/float(row[NUM_ACCT_OWNERS]))-(250000*float(row[NUM_ACCT_OWNERS])))*(float(row[NUM_ACCT_OWNERS])))
    
        file_output_data.append("\t".join(output_data))
    
        #file_output_data = ','.join(str(v) for v in value_list)
    
        if output_data[1] == "I":
            out_file = open(
            'U:\path_one.txt', 'w')
            out_file.write("\n".join(file_output_data))
            out_file.close()
    
        if output_data[1] == "S":
            out_file = open(
            'U:\path_two.txt', 'w')
            out_file.write("\n".join(file_output_data))
            out_file.close()
    


Answer: Your error is in the part:

    
    
    client_id = row[TID]
    client_id.replace("0", "x")
    client_id.replace("1", "d")
    client_id.replace("2", "h")
    client_id.replace("3", "g")
    client_id.replace("4", "v")
    client_id.replace("5", "n")
    client_id.replace("6", "m")
    client_id.replace("7", "q")
    client_id.replace("8", "w")
    client_id.replace("9", "r")
    client_id.replace("-", "u")
    output_data[0] = client_id
    

Go write an unit test for it and see what the code does. replace doesn't do
what you think it does.

