'_csv.writer' object has no attribute 'write'

Viewed 27521

I am not sure what the problem is here. I have a csv file I want to filter. I want to remove all lines starting with '@' and all lines where the third column is the string 'chrM'. Im basically setting my code up to be like the answer here:

TypeError: expected a character buffer object

But Im getting an error.

import re
import csv

inputSamFile = 'excerpt'
outSamFile = 'filternoM'

with open(inputSamFile) as inputSam, open(outSamFile, 'wt') as outSam:
    inputSamCont = csv.reader(inputSam, delimiter = '\t')
    outSamCont = csv.writer(outSam, delimiter = '\t')
    for line in inputSamCont:
        if line[0].startswith('@'):
            continue
        elif line[2] == 'chrM':
            continue
        else:
            outSamCont.write(line)

Traceback (most recent call last): File "filterMito.py", line 19, in outSamCont.write(ProcessLine(line)) AttributeError: '_csv.writer' object has no attribute 'write'

What am I doing wrong

2 Answers
Related