Python code reflection and modification
问题 Perhaps I'm not using the proper term, but I'm looking to take a block of Python code (in Python), get the token tree for the code, make some kind of modification, and re-assemble it to Python. For instance, consider this block of code: def x(y): b = 2 if y == b: foo(y) I would like to be able to take this and programmatically do this: def x(y): b = 2 if y == b: bar(y) I can't imagine that there's not a library that does something like this. Thanks in advance. EDIT Perhaps I wasn't entirely