Edit Python code programmatically

Alex noname9968 at gmail.com
Sat Feb 9 13:18:17 CET 2008

Steven D'Aprano wrote:
> On Sat, 09 Feb 2008 14:38:29 +0300, Alex wrote:
>> Which library could you recommend to perform simple editing of Python
>> code (from Python program)? 
> I'm not even sure such a library exists.
Yes they exist, that field is called "code-generation", "generative 
programming" etc.
>> For example, open *.py file, find specific
>> function definition, add another function call inside, find existing
>> call and change parameter value, etc.
> Why do you want to do that? I'm not sure what you're trying to 
> accomplish. Code refactoring? I imagine that's probably best done with 
> your text editor: at best, your editor will have dedicated refactoring 
> tools, and at worst, it will have global search and replace.
I don't feel like describing all ideas - it's nothing really intersting 
anyway, just a learning project (to get to know language features), but 
obviously it's not for regular programming - I know text editors can do 
that just fine. Simply in some situation I think instead of generating 
data I'd better generate some code.

More information about the Python-list mailing list