[Python-ideas] Modify inspect.getmembers() to return object members in source code order

Chris Angelico rosuav at gmail.com
Mon Mar 16 01:37:48 CET 2015


On Mon, Mar 16, 2015 at 11:29 AM, Cem Karan <cfkaran2 at gmail.com> wrote:
> On Mar 15, 2015, at 8:08 PM, Chris Angelico <rosuav at gmail.com> wrote:
>
>> On Mon, Mar 16, 2015 at 11:02 AM, Cem Karan <cfkaran2 at gmail.com> wrote:
>>> I'd like to suggest that inspect.getmembers() be modified to return elements in the order they are defined in the source code rather than in alphabetical order.
>>>
>>
>> I'm not sure that that's really possible, unless you also are
>> proposing that OrderedDict be used internally instead of a regular
>> dict for all namespaces. That information doesn't exist.
>
> That was what I was afraid of.

Nathaniel offered information which I hadn't known, which probably
solves your problem. You get line number info, and can sort by that -
just on the result of getmembers.

ChrisA


More information about the Python-ideas mailing list