Let's say I have a line in a text file output.dat
like this
in kB 16829.38785 17132.36275-14415.58515 72.67157 123.80624 17.02385
How can I split this string to 6 float objects, each contains 5 decimal points?
For now I am using the split by default (space).
import numpy as np
for line in open('output.dat'):
if line.find('in kB ') != -1:
stress = -np.array([float(a) for a in line.split()[2:]])
And as expected, this returns an error like this
ValueError: could not convert string to float: '17132.36275-14415.58515'
Edit: I want to make one thing clear, "-" means negative number, not just a connector. So I want to keep that after the split. The whole problem is exactly caused by when there is a negative result, the "-" occupies a space.