return [atok.get_text(n) for n in ast.walk(atok.tree) if isinstance(n, ast.
    expr) and not isinstance(n, (ast.Num, ast.Str))]
for expr in reversed(expand(
    'someDict["something"][some_module.someOtherDict["somethingElse"]]')):
    print(('print(%s)' % expr))
Divide a line of Python code into its parts