Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically editing Python source

Tags:

python

file-io

This is something that I think would be very useful. Basically, I'd like there to be a way to edit Python source programmatically without requiring human intervention. There are a couple of things I would like to do with this:

  1. Edit the configuration of Python apps that use source modules for configuration.

  2. Set up a "template" so that I can customize a Python source file on the fly. This way, I can set up a "project" system on an open source app I'm working on and allow certain files to be customized.

I could probably write something that can do this myself, but I can see that opening up a lot of "devil's in the details" type issues. Are there any ways to do this currently, or am I just going to have to bite the bullet and implement it myself?

like image 965
Jason Baker Avatar asked Aug 28 '08 14:08

Jason Baker


1 Answers

Python's standard library provides pretty good facilities for working with Python source; note the tokenize and parser modules.

like image 127
Carl Meyer Avatar answered Nov 15 '22 19:11

Carl Meyer