Re: Modify code with AST

2013-06-12 Thread Ronny Mandal
> I think the main problem is that you have to return the unchanged node (you > > return None which might be an indentation accident). I also had to take the > > add() FunctionDef out of the enclosing Module. So (I don't have codegen or > > is it part of the stdlib?): Thank you, my problem i

Re: Modify code with AST

2013-06-12 Thread Peter Otten
Ronny Mandal wrote: > Hello, > > I am trying to write a script which will parse a code segment (with > ast.parse()), locate the correct function/method node (by name) in the > resulting tree and replace this function (node) with another function > (node), e.g.: > > MyMod1.py: > > class FooBar()

Modify code with AST

2013-06-12 Thread Ronny Mandal
Hello, I am trying to write a script which will parse a code segment (with ast.parse()), locate the correct function/method node (by name) in the resulting tree and replace this function (node) with another function (node), e.g.: MyMod1.py: class FooBar(): def Foo(self): #I want to replace