Writting to specific location in a file

artixan at gmail.com artixan at gmail.com
Tue Feb 22 19:02:28 EST 2005


I have a database result set in a Python list. Each row is a tuple.
data = [(a_field,b_field,c_field,d_field,x_field,y_field,z_field)]

I need to loop thru this data and write each row to a text file.

f = open('out.txt','w')
for row in data:
    f.writelines(row)


My chanllenge  is that each field needs to have a exact specific
position in the output file.
For instance a_field needs to start at position 2 in the line, b_fields
at position 18 and so on, for all the fields on each line.


What is a way of approaching this problem. I was think of maybe
creating a Cheetah template file. Is there a simple way to go?

Can anyone point me to a possible way of doing this?


Thanks a lot,

Arnaldo




More information about the Python-list mailing list