Let's parse it up with Parsley. Following the standard example of other parsing frameworks, we're going to build a standard mathematical expression parser. Unlike other frameworks like PyParsing, Parsley grammars are defined in a giant string, rather than a special DSL.
Let's start with something that can interpret a collection of digits, and spit out a number:
import parsley
grammar = """
digit = :x ?(x in '0123456789') -> x
number = <digit+> :ds -> int(''.join(ds))
"""
parse_digits = parsley.make_parser(grammar)
And now we can use it:
>>> from digitparser import parse_digits
>>> parse_digits("12345")
12345
Don't ask me how the hell that works or what the hell that means I stole it from washort and he doesn't know either apparently.