I'm trying to get all the members of a class, but in order... Here's a MWE
class example:
def __init__(self):
self.c = 3
self.z = 5
self.a = 5
self.b = 3
ex = example()
members = [attr for attr in dir(ex) if not \
callable(getattr(ex, attr)) and not attr.startswith("__")]
print(members)
This prints:
['a', 'b', 'c', 'z']
For the life of me, I can't figure out why its alphabetizing things. Ideally, I want it as ['c','z','a','b']