Manipulating Python Source

W

Wilson

Hi,

I'm wondering if there are any tools available or simple methods for
taking a python source file and parsing into some hierarchical format,
like the ConfigParser. I'd like to be able to do something like the
following:

test.py:
-------------------------------------------------------

""" This is an example """

class MyClass(ParentA, ParentB):
def some_func(self, foo, bar):
self.baz = "batman"

class MyClass2(object):
""" This is an example class """
def __init__(self):
self.a = "Blablabla"

And from the interpreter:
import magicalParser
parsed = magicalParser.parse(test.py)
parsed.getClasses() ["MyClass", "MyClass2"]
parsed.docString " This is an example "
parsed.removeClass("MyClass2")
parsed.getClasses() ["MyClass"]
parsed.MyClass.getFuncs() ["some_func"]
parsed.MyClass.some_func.addParam("baz")
parsed.printSource()
""" This is an example """

class MyClass(ParentA, ParentB):
def some_func(self, foo, bar, baz):
self.baz = "batman"
Or something that would yield the above effect. Any ideas?

Thanks,
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top