Before python 3.6 it was difficult to get attributes order from a class. Let’s say, for instance, you want to create a listing class which contains columns to display :
1 2 3 4 5 6 7 8 9 10 11 12 13 |
class Column(object): pass class Listing(object): col1 = Column() col2 = Column() col3 = Column() col4 = Column() col5 = Column() col6 = Column() print( [ k for k in Listing.__dict__.keys() if '__' not in k ] ) |
With python 2.7 you will get :
1 |
['col6', 'col4', 'col5', 'col2', 'col3', 'col1'] |
With python 3.5 you will get :
1 |
['col3', 'col1', 'col4', 'col5', 'col2', 'col6'] |
And finally, with python 3.6, there is no problem any more : attributes…