Oct-06-2019, 08:56 AM
(This post was last modified: Oct-06-2019, 08:56 AM by Gribouillis.)
Here is a new version. You don't need to import the io module.
def func(s): t = re.sub(r'\s+', '', s) sign = True for tok in generate_tokens(iter([t, '']).__next__): if sign and tok[1] in ('-', '+'): sign = False continue if tok[0] == NUMBER: return ast.literal_eval(t[:tok[3][1]]) return 0 return 0If there is still an error, please give full bug report!