Object '_csv.writer' does not have attribute 'write'

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

TypeError: character buffer object expected

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 (last last call): File "filterMito.py", line 19, in outSamCont.write (ProcessLine (line)) AttributeError: '_csv.writer' does not have the attribute 'write'

What am I doing wrong

+4
source share
2 answers

Perhaps you are looking .writerow().

, , , .write(), csv.writer .writerow().

+3

, .

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

:

outSamCont = csv.writer(outSam, delimiter = '\t')

.write():

outSamCont.write(line)

(,

outSamCont.write(ProcessLine(line)) 

, , ).

a csv.writer write, , . . csv.writer , , .

+2

All Articles