[Solved] Finding 9 characters before a particular string in Python [closed]


line="2020-08-12 13:45:04 0.86393 %contrastWeber"

position = line.index('%contrastWeber')

if position >= 0:
    starting = position - 9
    if starting < 0:
        starting = 0
    ending = position
    print(line[starting : ending])
else:
    print('is not found')

solved Finding 9 characters before a particular string in Python [closed]