Module listing in order.

Wildemar Wildenburger wildemar at freakmail.de
Fri May 25 20:46:33 EDT 2007


Peter Otten wrote:
> 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']
>
>   

Good God! Is there *anything* that python does not already do? I hardly 
feel the need to write programs anymore ...
Its really 80% like of the questions that are asked here get answered 
along the lines of:

import some_fancy_module

solution = some_fancy_module.exactly_the_right_function_to_solve(problem)



Kinda scary ... :)
W



More information about the Python-list mailing list