The lines that you want to parse are Python code, so use the built-in parsing capabilities of Python. You can parse with the
ast module, or simply extract a sequence of tokens with
tokenize.tokenize()
>>> from tokenize import tokenize
>>> import io
>>> line = "1/2 + 1/2*i + 1/2*j + 1/2*k\n"
>>>
>>> for token in tokenize(io.BytesIO(line.encode()).readline):
... print(token)
...
TokenInfo(type=63 (ENCODING), string='utf-8', start=(0, 0), end=(0, 0), line='')
TokenInfo(type=2 (NUMBER), string='1', start=(1, 0), end=(1, 1), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=54 (OP), string='/', start=(1, 1), end=(1, 2), line='1/2 + 1/2*i + 1/2*j + 1/
2*k\n')
TokenInfo(type=2 (NUMBER), string='2', start=(1, 2), end=(1, 3), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=54 (OP), string='+', start=(1, 4), end=(1, 5), line='1/2 + 1/2*i + 1/2*j + 1/
2*k\n')
TokenInfo(type=2 (NUMBER), string='1', start=(1, 6), end=(1, 7), line='1/2 + 1/2*i + 1/2*j + 1/2*k\n')
TokenInfo(type=54 (OP), string='/', start=(1, 7), end=(1, 8), line='1/2 + 1/2*i + 1/2*j + 1/
2*k\n')
TokenInfo(type=2 (NUMBER), string='2', start=(1, 8), end=(1, 9), line='1/2 + 1/2*i + 1/2*j + 1/2*k\n')
TokenInfo(type=54 (OP), string='*', start=(1, 9), end=(1, 10), line='1/2 + 1/2*i + 1/2*j + 1
/2*k\n')
TokenInfo(type=1 (NAME), string='i', start=(1, 10), end=(1, 11), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=54 (OP), string='+', start=(1, 12), end=(1, 13), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=2 (NUMBER), string='1', start=(1, 14), end=(1, 15), line='1/2 + 1/2*i + 1/2*j + 1/2*k\n')
TokenInfo(type=54 (OP), string='/', start=(1, 15), end=(1, 16), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=2 (NUMBER), string='2', start=(1, 16), end=(1, 17), line='1/2 + 1/2*i + 1/2*j + 1/2*k\n')
TokenInfo(type=54 (OP), string='*', start=(1, 17), end=(1, 18), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=1 (NAME), string='j', start=(1, 18), end=(1, 19), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=54 (OP), string='+', start=(1, 20), end=(1, 21), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=2 (NUMBER), string='1', start=(1, 22), end=(1, 23), line='1/2 + 1/2*i + 1/2*j
+ 1/2*k\n')
TokenInfo(type=54 (OP), string='/', start=(1, 23), end=(1, 24), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=2 (NUMBER), string='2', start=(1, 24), end=(1, 25), line='1/2 + 1/2*i + 1/2*j
+ 1/2*k\n')
TokenInfo(type=54 (OP), string='*', start=(1, 25), end=(1, 26), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=1 (NAME), string='k', start=(1, 26), end=(1, 27), line='1/2 + 1/2*i + 1/2*j +
1/2*k\n')
TokenInfo(type=4 (NEWLINE), string='\n', start=(1, 27), end=(1, 28), line='1/2 + 1/2*i + 1/2
*j + 1/2*k\n')
TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')
>>>
Another solution, if your lines all have this exact structure that look like the computation of a quaternion would be to load a quaternion module, define the names i, j, k in the current namespace and simply evaluate the expression to get a quaternion.
The strange thing in these lines however is that a line such as
1/2 + 1/2*i + 1/2*j + 1/2*k
in a Python program computes a result but then forgets it immediatly because it is not stored somewhere nor used in a call.