value error
Gerhard Häring
gh at ghaering.de
Thu Apr 23 11:14:13 EDT 2009
Francesco Pietra 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: ''
Instead of L[24-28] you want L[24:28]. Otherwise it's L[-4] ;-)
-- Gerhard
More information about the Python-list
mailing list