[Tutor] creating a regularly placed fields in a line
Bala subramanian
bala.biophysics at gmail.com
Wed Apr 25 17:17:04 CEST 2012
Friends,
I wrote a small piece of code (given below). The aim is to take each line
in a file, split the fields, replace the first four fields and then write
the new lines in a output file. The input and output are given in the
attached file. The output contains fields which are irregularly placed
depending up on the size of the field. I am thinking to fix the size of
each field. Kindly provide me some way on how i can do the same or a better
way to fix placement of fields.
with open('tmp') as tp:
for line in tp:
line=line.split()
p1=atm_type[line[0]];p2=atm_type[line[1]]
p3=atm_type[line[2]];p4=atm_type[line[3]]
new='\t'.join(line[4:10])
bond.write(' %s\t%s\t%s\t%s\t%s\n' % (p1,p2,p3,p4,new) )
--
C. Balasubramanian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120425/d22ac614/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.output
Type: application/octet-stream
Size: 1025 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20120425/d22ac614/attachment.obj>
More information about the Tutor
mailing list