You could use a regular expression:
import re
psi_values = re.compile(r'PSI.*?(\d+)-(\d+)')
psi_low, psi_high = psi_values.search(var_psi).groups()
If you need the values to be integers, use map(int, ...)
to apply the int()
function to each matched group:
psi_low, psi_high = map(int, psi_values.search(var_psi).groups())
For your code sample, that gives me:
>>> psi_low, psi_high
(101, 121)