I am new-ish to python and need to write a short program which will take a file with many lines of sets of coordinates alongside a defined variable of a series of letters and out a 3 columned file with columns x, y, and letter.
the input file has each line in the form of
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (-1,7), (-1, 8), (0, 8)]
and there is a defined variable Prot which has the same length as the number of coordinate pairs in each line of the input file (0.traj).

I've tried having it readlines and treat it like a list but I can't get it to work.
I need a different output file for each line in the file (number of lines change per file) but the defined variable Prot only changes once per file.

Thanks in advance for any help.

part of my thinking was to maybe replace all the ( with '( and ) with )' and kill the white space between coordinates that way it would look more like a list. a) would this work b)how do you do it c) would it read like a list with nested tuples then

I post my answer here too (i did it first on your other thread)
you've got an easy way of doing this :

for data in datas:
    exec ("lst=%s" % data)
    for i, coord in enumerate(lst):
        for elt in coord:
            print elt,
        print Prot[i]

This is to be adapted for your exact need

This article has been dead for over six months. Start a new discussion instead.