On Thu, Apr 23, 2009 at 3:59 PM, Francesco Pietra <chiendar...@gmail.com>wrote:
> hi: > with script > > data = open('134-176_rectified_edited.pdb', 'r') > outp = open('134-176_renumbered.pdb', 'w') > > for L in data: > if L[3] == 'M': > L = L[:24] + "%4d" % (int(L[24-28])+133) + L[28:] > outp.write(L) > > > i wanted to modify lines of the type: > ATOM 1 HH31 ACE 1 1.573 1.961 0.769 1.00 0.00 > H > > to add 133 to column 25, getting 134 there, and so on for next lines 2 > -> 135, 3 -> 136, etc. > > > i must have heavily messed things because the file was not even read: > > $ python renumber.py 134-176_rectified.pdb > Traceback (most recent call last): > File "renumber.py", line 6, in <module> > L = L[:24] + "%4d" % (int(L[24-28])+133) + L[28:] > ValueError: invalid literal for int() with base 10: '' > > > > thanks for having an expert look > > chiendarret > -- > http://mail.python.org/mailman/listinfo/python-list > I wrote this function the other day for something similar I needed to do, you may find it useful: def chunk_line(line, steps): """Return a list of chunks from a string, with sizes as specified by the list steps. >>> line = '1121231234' >>> steps = [1,2,3,4] >>> chunk_line(line, steps) ['1', '12', '123', '1234'] """ result = [] for step in steps: result.append(line[:step]) line = line[step:] return result
-- http://mail.python.org/mailman/listinfo/python-list