can list be converted into string

Posted by PARIJAT on Stack Overflow See other posts from Stack Overflow or by PARIJAT
Published on 2010-05-25T15:29:33Z Indexed on 2010/05/25 15:31 UTC
Read the original article Hit count: 149

Filed under:

Actually i have extracted some data from the file and want to write it in the file 2 but the program says 'sequence item 1: expected string, list found', I want to know how i can convert buffer[] ie string into sequence, so that it could be saved in file 2...I am new to the python please help*

file = open('/ddfs/user/data/k/ktrip_01/hmm.txt','r')

file2 = open('/ddfs/user/data/k/ktrip_01/hmm_write.txt','w')

buffer = []

rec = file.readlines()

for line in rec :

    field = line.split()

    print '>',field[0]

    term = field[0]

    buffer.append(term)

    print   field[1], field[2],   field[6], field[12]

    term1 = field [1]

    buffer.append(term1)

    term2 = field[2]

    buffer.append[term2]

    term3 = field[6]

    buffer.append[term3]

    term4 = field[12]

    buffer.append[term4]

    file2.write(buffer)

file.close()

file2.close()

© Stack Overflow or respective owner

Related posts about python