value error
Ben Finney
ben+python at benfinney.id.au
Thu Apr 23 11:11:22 EDT 2009
Francesco Pietra <chiendarret at gmail.com> writes:
> $ 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: ''
For this reason, it's best to break up big complex expressions like this
into a sequence of simpler statements, so when one of them fails it's
easier to see what went wrong.
In this case, it's because you have L[24-28] where that's almost
certainly not what you mean. It calculates 24-28, getting -4; then uses
that value as an index into L.
You probably wanted to say L[24:28], a slice instead of a single index.
But, really, why are all these magic numbers littering the source,
instead of using named values? You're writing code that will be a
nightmare to maintain.
--
\ “A lot of people are afraid of heights. Not me, I'm afraid of |
`\ widths.” —Steven Wright |
_o__) |
Ben Finney
More information about the Python-list
mailing list