I need to retrieve the list of attributes of a Python module.
The catch, and this is where this question differs e.g. from this one, is that I want the list ordered according to the order they appear in the module.
As an example, consider the module
# a_module.py
b1 = 1
a0 = 1
a1 = 2
I want the list ['b1', 'a0', 'a1']
.
What I've tried:
>>> import a_module
>>> dir(a)
[..., 'a0', 'a1', 'b1']
>>> from inspect import getmembers
>>> [x[0] for x in getmembers(a_module)]
[..., 'a0', 'a1', 'b1']
Is there any way of getting the list without having to parse the file?