Module listing in order.
Peter Otten
__peter__ at web.de
Fri May 25 15:21:33 EDT 2007
Ramashish Baranwal wrote:
>> > I want a way to get the contents in the order of their declaration,
>> > i.e. [B, A, D]. Does anyone know a way to get it?
>>
>> My suggestion would be to actually parse the text of the module. "Brute
>> force" is what it's called ;). But doing so with, say, pyparsing
>> shouldn't be *very* difficult.
> Nevertheless, it would be interesting to see how it can be done.:)
>>> import pyclbr
>>> classes = pyclbr.readmodule("mymodule")
>>> sorted(classes, key=lambda name: classes[name].lineno)
['B', 'A', 'D']
Peter
More information about the Python-list
mailing list