I am trying to read python file, make some changes (construct product of functions and inline them in one) and write it back to files.
Python provide ast module, which can parse its code to ast, but has no method for reverse transition, I know there are some libraries, but I can't use them. I've tried to compile tree to code object and them get its source, but now my method produce only part of file. What am I doing wrong?
import ast
import inspect
module_path = "python_file.py"
with file(module_path, "r") as f:
result = ast.parse(f.read(), module_path)
print(ast.dump(result, include_attributes=True))
result = compile(result, module_path, mode='exec')
result = inspect.getsource(result)
print(result)